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. Thanks for all your past and future contributions.

How to prevent symbol collisions between GTK+ and Qt

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N900, Linux desktop
Platform(s): Maemo
Created: gnuton (22 Dec 2010)
Last edited: hamishwillee (11 Oct 2012)



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.

#include <QtCore/QCoreApplication>
#include <gtk/gtk.h>
int main(int argc, char *argv[])
QCoreApplication a(argc, argv);
return a.exec();

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,
from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
from /usr/include/gtk-2.0/gdk/gdk.h:32,
from /usr/include/gtk-2.0/gtk/gtk.h:32,
from ../gtk/main.cpp:3:
/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,
from ../gtk/main.cpp:3:
/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.

#include <QtCore/QCoreApplication>
#undef signals // Collides with GTK symbols
#include <gtk/gtk.h>


You can build successfully Qt applications which make use of GTK+ widgets.

This page was last modified on 11 October 2012, at 01:17.
55 page views in the last 30 days.