Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using glib and gtk with Qt
QtWS25 Last Chance

Using glib and gtk with Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    masa4
    wrote on last edited by
    #1

    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 PKGCONFIGs 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?

    jsulmJ 1 Reply Last reply
    0
    • S Offline
      S Offline
      stryga42
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      1
      • M masa4

        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 PKGCONFIGs 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?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        1
        • S stryga42

          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.

          M Offline
          M Offline
          masa4
          wrote on last edited by
          #4

          @stryga42 I wont use gtk for my UI, but the common project includes gtk, and uses it in inner test programs. I am not sure how can i isolate them. Thanks anyway.

          1 Reply Last reply
          0
          • jsulmJ jsulm

            @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

            M Offline
            M Offline
            masa4
            wrote on last edited by
            #5

            @jsulm Thank you, that was what i found. So only easy option is converting signal slots to their macro names.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              masa4
              wrote on last edited by
              #6

              By the way easiest solution i found is: adding #undef signals before glib includes, and after it #define signals again.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved