Opened 7 years ago

Last modified 7 years ago

#11876 new Bugs

Boost.Graph conflicts with Qt's foreach macro

Reported by: richel@… Owned by: Jeremiah Willcock
Milestone: To Be Determined Component: graph
Version: Boost 1.54.0 Severity: Problem
Keywords: Graph BGL Qt Cc:

Description

This is a similar problem as https://svn.boost.org/trac/boost/ticket/6455, where the Qt foreach macro conflicts with the boost::foreach::tag in file /usr/include/boost/foreach.hpp.

This is a simple Qt example that reproduces the error (also supplied as an attachment):

#include <boost/graph/adjacency_list.hpp>
#include <QCoreApplication>
#include <fstream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

int main(int argc, char *argv[])
{
  QCoreApplication a(argc, argv);

  std::ofstream f("filename.dot");
  boost::write_graphviz(
    f,
    boost::adjacency_list<>()
  );
  return a.exec();
}

For the following Qt Creator project file:

QT       += core
QT       -= gui
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp

The error given is:

In file included from /usr/include/boost/graph/graphviz.hpp:35:0,
                 from ../CppBoostGraphAndQtConflictQtConsole/main.cpp:5:
/usr/include/boost/foreach.hpp:169:42: error: 'boost::Q_FOREACH::tag' has not been declared
 boost_foreach_is_lightweight_proxy(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; }

The error does not occur if 'boost/graph/adjacency_list.hpp' is #included either before QCoreApplication or after. This is a workaround.

I cannot see if this error is still present in later versions of Boost. If it is still present, I hope I have contributed in letting Boost.Graph and Qt work together seamlessly.

Attachments (1)

CppBoostGraphAndQtConflictQtConsole.zip (834 bytes ) - added by richel@… 7 years ago.
Qt Creator project that reproduces the compile error

Download all attachments as: .zip

Change History (2)

by richel@…, 7 years ago

Qt Creator project that reproduces the compile error

comment:1 by viboes, 7 years ago

Component: Nonegraph
Owner: set to Jeremiah Willcock
Note: See TracTickets for help on using tickets.