Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
How to prevent symbol collisions between GTK+ and Qt
Including GTK+ headers in Qt applications is not straightforward since both frameworks define the symbol "signals" which leads the building process to fail with some error messages. This article explains how to prevent Symbol collisions,
To use GTK+ functions you need one of the following environments:
- Maemo SDK
- Nokia Qt SDK with Maemo target
- Any Linux distro with Qt and GTK+ development files
The following code is a minimal application which includes a GTK+ header.
int main(int argc, char *argv)
QCoreApplication a(argc, argv);
Since Qt and GTK define the "signals" symbol, the gcc compiler aborts the building process, printing out the following error messages:
Running build steps for project gtk...
Configuration unchanged, skipping qmake step.
Starting: "/usr/bin/make" -w
make: Entering directory `/home/gnuton/gtk-build-desktop'
g++ -c -pipe -O2 -pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../gtk -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I../gtk -I. -o main.o ../gtk/main.cpp
In file included from /usr/include/glib-2.0/gio/gio.h:48,
/usr/include/glib-2.0/gio/gdbusintrospection.h:151: error: expected unqualified-id before ‘protected’
/usr/include/glib-2.0/gio/gdbusintrospection.h:151: error: expected ‘;’ before ‘protected’
In file included from /usr/include/gtk-2.0/gtk/gtk.h:48,
/usr/include/gtk-2.0/gtk/gtkbindings.h:78: error: expected unqualified-id before ‘protected’
/usr/include/gtk-2.0/gtk/gtkbindings.h:78: error: expected ‘;’ before ‘protected’
make: *** [main.o] Error 1
make: Leaving directory `/home/gnuton/gtk-build-desktop'
The process "/usr/bin/make" exited with code 2.
Error while building project gtk (target: Desktop)
When executing build step 'Make'
To compile the previous code you have to undefine the colliding symbol before including the GTK header.
#undef signals // Collides with GTK symbols
You can build successfully Qt applications which make use of GTK+ widgets.