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
Forum Updated to NodeBB v4.3 + New Features

Using glib and gtk with Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.4k Views 1 Watching
  • 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 12 Jan 2023, 08:35 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?

    J 1 Reply Last reply 12 Jan 2023, 17:31
    0
    • S Offline
      S Offline
      stryga42
      wrote on 12 Jan 2023, 17:28 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 13 Jan 2023, 04:28
      1
      • M masa4
        12 Jan 2023, 08:35

        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?

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 12 Jan 2023, 17:31 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 13 Jan 2023, 04:30
        1
        • S stryga42
          12 Jan 2023, 17:28

          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 13 Jan 2023, 04:28 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
          • J jsulm
            12 Jan 2023, 17:31

            @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 13 Jan 2023, 04:30 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 13 Jan 2023, 07:11 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

              2/6

              12 Jan 2023, 17:28

              topic:navigator.unread, 4
              • Login

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