Q:

'boost::Q_FOREACH' has not been declared

In my code I use boost (1.52) and qt (4.8.3) and the first compilation error I have is the following
D:\qt\4.8.3\x86_64-w64-mingw32\include/QtCore/qglobal.h:2439:21: error: 'boost::Q_FOREACH' has not been declared 

Is it a bug?

A:

Start your .cpp-file with #include <QObject>.
For instance, this:
#include <boost/foreach.hpp>
#include <QObject>
#include <boost/multi_index/hashed_index.hpp>

... compiles to error: 'boost::Q_FOREACH' has not been declared whereas this:
#include <QObject>
#include <boost/foreach.hpp>
#include <boost/multi_index/hashed_index.hpp>

... compiles just fine.

qglobal.h (included by all Qt headers) creates a macro #define foreach Q_FOREACH which expands in references like boost::foreach::foo or namespace foreach, but only in references encountered after the macro declaration. Be defining the macro early all references are expanded in the same way.
I used hashed_index.hpp in the example because it happens to use the foreach namespace. It's ugly to rename a namespace but it doesn't affect the client code.

A:

For anyone else having this issue, another workaround is to have the Boost includes before the Qt includes

A:

This could be caused by the conflict between boost and Qt. See this post
Someone suggested using CONFIG += no_keywords in your project file.
But I've also seen a ticket to fix this issue closed.. https://svn.boost.org/trac/boost/ticket/6455
So not sure whether this could help your problem

