Weird compiler error while moving code from console to GUI



  • 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!



  • Ι 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)



  • Try using QT_NO_KEYWORDS in files that need that header file.



  • 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?)



  • 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!



  • 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 :/



  • 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.



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



  • @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



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



  • 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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.