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. Weird compiler error while moving code from console to GUI
Forum Updated to NodeBB v4.3 + New Features

Weird compiler error while moving code from console to GUI

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 6.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.
  • A Offline
    A Offline
    alexandros
    wrote on last edited by
    #1

    Hello developers :)
    I have made a sample terminal application mainly for testing purposes with the initial purpose to include it into my main application, when I made the sample run well. So, I made the sample run pretty well, and what it does is to display a notification (in ubuntu) and change it contents and icons fully without killing it. But that doesn't really matter. What matters is that the sample terminal application DOES work fine and it runs very well.
    So, the project file of my terminal application looks like:
    @
    TEMPLATE = app
    TARGET =
    DEPENDPATH += .
    INCLUDEPATH += .
    CONFIG += link_pkgconfig
    PKGCONFIG += libnotify
    SOURCES += update-notifications.cpp
    @
    and my main's program project file:
    @
    TEMPLATE = app
    TARGET =
    DEPENDPATH += .
    INCLUDEPATH += .
    QT += dbus
    LIBS += -lcv -lhighgui
    CONFIG += link_pkgconfig
    PKGCONFIG += libnotify

    Input

    HEADERS += about.h
    extras.h
    glob.h
    history.h
    mainwindow.h
    MyCameraWindow.h
    preferences.h
    properties.h
    QOpenCVWidget.h
    screenshot.h
    statistics.h
    FORMS += about.ui
    extras.ui
    history.ui
    mainwindow.ui
    preferences.ui
    properties.ui
    screenshot.ui
    statistics.ui
    SOURCES += about.cpp
    extras.cpp
    history.cpp
    main.cpp
    mainwindow.cpp
    MyCameraWindow.cpp
    preferences.cpp
    properties.cpp
    QOpenCVWidget.cpp
    screenshot.cpp
    statistics.cpp
    RESOURCES += icons.qrc
    @

    As you see, both the sample and the main project files have:
    @CONFIG += link_pkgconfig
    PKGCONFIG += libnotify@
    This does the linking to the library I want to use.
    Also, both the sample code and my main code starts by including the library in which I linked to from the project file:
    @#include <libnotify/notify.h>@

    Now, even if I let my main project like this, I mean by only editing its project file and adding the
    @#include <libnotify/notify.h>@
    I get a bunch of errors NOT about my code, but about the included library or some of its dependencies:
    @/usr/include/glib-2.0/gio/gdbusintrospection.h:151: error: expected unqualified-id before ‘protected’@
    I mean, how weird can this be?
    i did exactly the same things both in the GUI and in the sample terminal application and I get errors from the GUI one. Can anyone explain me why is this happening? Why the compiler finds errors about the libraries in the GUI while the terminal application with exactly the same code runs OK?

    Thanks in advance for any answers!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexandros
      wrote on last edited by
      #2

      Ι was answered that it may be the fact that I included C libraries in C++. I extern "C" the library but still no luck, but I guess that this is not the point in this forum (it is a C++ question, not a Qt one)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        loladiro
        wrote on last edited by
        #3

        Try using QT_NO_KEYWORDS in files that need that header file.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexandros
          wrote on last edited by
          #4

          Hey, thanks for the answer! I have asked this question in several forums and it's the first answer I get... (!)
          Could you be more specific please :) ?
          Where should I place QT_NO_KEYWORDS? (i mean it seems not to be a function, neither a name type and the project file is about all the files, so, where do I place it?)

          1 Reply Last reply
          0
          • L Offline
            L Offline
            loladiro
            wrote on last edited by
            #5

            I'm sorry, I was kinda in a hastle of getting home when I posted that ;).
            What i meant is using
            @
            #define QT_NO_KEYWORDS
            @
            in every file where you have that problem. You'll also have to use Q_SIGNALS, Q_SLOTS and Q_EMIT instead of signals, slots, emit, respectively. The actual problem is that in that header file there is a member called "signals" which of course doesn't work well if Qt uses that as a keyword ;)

            EDIT: At the very beginning before any other includes, that is!

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alexandros
              wrote on last edited by
              #6

              You must be quite a genius so as to guess that the word 'signals' made the trouble or I am the one who find it difficult to find from the info I've given from the 1st post?
              Yes :) The part that seems to have problem is:
              @
              GDBusSignalInfo **signals;
              @

              Thanks again, and, is there any way so as to solve this problem and not by calling
              QT_NO_KEYWORDS ? Because the program is quite big and has a lot of signal (emit etc) calls and it needs a lot of work to be done :/

              1 Reply Last reply
              0
              • L Offline
                L Offline
                loladiro
                wrote on last edited by
                #7

                There should be no problem if there is not Qt header included before it. Also, why don't you just use Qt Creator to batch replace all occurrences of signals, slots and emit (You can do it either for just one project or for all files in a specific directory using Qt Creator's advanced search options).
                [quote]You must be quite a genius so as to guess that the word ‘signals’ made the trouble or I am the one who find it difficult to find from the info I’ve given from the 1st post?[/quote]
                While it is true that I'm a genius ;), I'm also just the usual geek using Linux, so I had a look at the file.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alexandros
                  wrote on last edited by
                  #8

                  Good to know that there seem to be lots of Linux users around :)

                  So, because I didn't get it 100%, I have to replace 'SLOT()' 'SIGNAL()' (both of them used while using connect()) and 'emit' with Q_SLOTS, Q_SIGNALS and Q_EMIT repsectively?

                  Or Q_SIGNALS is referring to the declaration of a signal (signals:) in a header file?

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    loladiro
                    wrote on last edited by
                    #9

                    @slots: -> Q_SLOTS:
                    signals: -> Q_SIGNALS:
                    emit -> Q_EMIT@
                    http://doc.qt.nokia.com/4.7/qobject.html#Q_SIGNALS

                    EDIT: fixed, sorry for the confusion

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alexandros
                      wrote on last edited by
                      #10

                      Yeah! Thanks again :) I'm gonna try it right now and I'll post back if I have any problems :)

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        alexandros
                        wrote on last edited by
                        #11

                        Ok :)
                        It run very very well, a side notice btw, if I edited the SLOT() and SIGNAL() on the QObject::connect() function I got error, without it it run OK ;)
                        But I had to replace the other name types :D

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          loladiro
                          wrote on last edited by
                          #12

                          You're right, I made a mistake in the original post. Sorry for the confusion. I never had to use those macros myself ;)

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            alexandros
                            wrote on last edited by
                            #13

                            Hm, I had to use this library in one more file and there this definition doesn't seem to solve the problem :/

                            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