Using glib and gtk with Qt
-
I have a common project which is developed using glib, gtk and some other libraries. I will use this common project's headers&source files in my project. I added required
PKGCONFIG
s to my.pro
file. It builds succesfully. But when i include header files of common project to my project and try to build project:/usr/include/qt6/QtCore/qtmetamacros.h:45:20: error: expected unqualified-id before ‘public’ 45 | # define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal) | ^~~~~~ /usr/include/qt6/QtCore/qtmetamacros.h:41:22: note: in expansion of macro ‘Q_SIGNALS’ 41 | # define signals Q_SIGNALS | ^~~~~~~~~ /usr/include/glib-2.0/gio/gdbusintrospection.h:157:25: note: in expansion of macro ‘signals’ 157 | GDBusSignalInfo **signals; | ^~~~~~~ /usr/include/qt6/QtCore/qtmetamacros.h:45:20: error: expected unqualified-id before ‘public’ 45 | # define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal) | ^~~~~~ /usr/include/qt6/QtCore/qtmetamacros.h:41:22: note: in expansion of macro ‘Q_SIGNALS’ 41 | # define signals Q_SIGNALS | ^~~~~~~~~ /usr/include/gtk-3.0/gtk/gtkbindings.h:103:21: note: in expansion of macro ‘signals’ 103 | GtkBindingSignal *signals; | ^~~~~~~
I saw a thing
CONFIG += no_keywords
, that can maybe solve the problem(i didnt try it yet) but i will need to change all signal, slot, emit keywords in my project. Any better way? And why this happening? Because of glib use same keywords or something? -
It seems that the token signals is used as a variable name in glib and defined as a macro in Qt6. Since macro substitution happens very early there is not much you can do.
Maybe you can isolate gtk and Qt so that Qt includes (which provide the annoying macro definition) are never processed before gtk includes happen.
General remark: Mixing direct gtk and Qt in one GUI may create "strange" results - I ran into such a problem years ago, see this post. So it may be a good idea to keep things separated anyway. -
I have a common project which is developed using glib, gtk and some other libraries. I will use this common project's headers&source files in my project. I added required
PKGCONFIG
s to my.pro
file. It builds succesfully. But when i include header files of common project to my project and try to build project:/usr/include/qt6/QtCore/qtmetamacros.h:45:20: error: expected unqualified-id before ‘public’ 45 | # define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal) | ^~~~~~ /usr/include/qt6/QtCore/qtmetamacros.h:41:22: note: in expansion of macro ‘Q_SIGNALS’ 41 | # define signals Q_SIGNALS | ^~~~~~~~~ /usr/include/glib-2.0/gio/gdbusintrospection.h:157:25: note: in expansion of macro ‘signals’ 157 | GDBusSignalInfo **signals; | ^~~~~~~ /usr/include/qt6/QtCore/qtmetamacros.h:45:20: error: expected unqualified-id before ‘public’ 45 | # define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal) | ^~~~~~ /usr/include/qt6/QtCore/qtmetamacros.h:41:22: note: in expansion of macro ‘Q_SIGNALS’ 41 | # define signals Q_SIGNALS | ^~~~~~~~~ /usr/include/gtk-3.0/gtk/gtkbindings.h:103:21: note: in expansion of macro ‘signals’ 103 | GtkBindingSignal *signals; | ^~~~~~~
I saw a thing
CONFIG += no_keywords
, that can maybe solve the problem(i didnt try it yet) but i will need to change all signal, slot, emit keywords in my project. Any better way? And why this happening? Because of glib use same keywords or something?@masa4 To add to @stryga42 take a look at https://doc.qt.io/qt-5/signalsandslots.html#using-qt-with-3rd-party-signals-and-slots
-
It seems that the token signals is used as a variable name in glib and defined as a macro in Qt6. Since macro substitution happens very early there is not much you can do.
Maybe you can isolate gtk and Qt so that Qt includes (which provide the annoying macro definition) are never processed before gtk includes happen.
General remark: Mixing direct gtk and Qt in one GUI may create "strange" results - I ran into such a problem years ago, see this post. So it may be a good idea to keep things separated anyway. -
@masa4 To add to @stryga42 take a look at https://doc.qt.io/qt-5/signalsandslots.html#using-qt-with-3rd-party-signals-and-slots