Namespaces
Variants
Actions
Revision as of 04:17, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to prevent symbol collisions between GTK+ and Qt

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia N900, Linux desktop

Compatibility
Platform(s): Maemo

Article
Created: gnuton (22 Dec 2010)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

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,

Preconditions

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

Code

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>

Postconditions

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

275 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved