July 7, 2011

alexandros alexandros
Ant Farmer
114 posts

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:

  1. TEMPLATE = app
  2. TARGET =
  3. DEPENDPATH += .
  4. INCLUDEPATH += .
  5. CONFIG += link_pkgconfig
  6. PKGCONFIG += libnotify
  7. SOURCES += update-notifications.cpp

and my main’s program project file:
  1. TEMPLATE = app
  2. TARGET =
  3. DEPENDPATH += .
  4. INCLUDEPATH += .
  5. QT += dbus
  6. LIBS += -lcv -lhighgui
  7. CONFIG += link_pkgconfig
  8. PKGCONFIG += libnotify
  9.  
  10. # Input
  11. HEADERS += about.h \
  12.            extras.h \
  13.            glob.h \
  14.            history.h \
  15.            mainwindow.h \
  16.            MyCameraWindow.h \
  17.            preferences.h \
  18.            properties.h \
  19.            QOpenCVWidget.h \
  20.            screenshot.h \
  21.            statistics.h
  22. FORMS += about.ui \
  23.          extras.ui \
  24.          history.ui \
  25.          mainwindow.ui \
  26.          preferences.ui \
  27.          properties.ui \
  28.          screenshot.ui \
  29.          statistics.ui
  30. SOURCES += about.cpp \
  31.            extras.cpp \
  32.            history.cpp \
  33.            main.cpp \
  34.            mainwindow.cpp \
  35.            MyCameraWindow.cpp \
  36.            preferences.cpp \
  37.            properties.cpp \
  38.            QOpenCVWidget.cpp \
  39.            screenshot.cpp \
  40.            statistics.cpp
  41. RESOURCES += icons.qrc

As you see, both the sample and the main project files have:

  1. CONFIG += link_pkgconfig
  2. 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:
  1. #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

  1. #include <libnotify/notify.h>

I get a bunch of errors NOT about my code, but about the included library or some of its dependencies:
  1. /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!

12 replies

July 12, 2011

alexandros alexandros
Ant Farmer
114 posts

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

July 12, 2011

loladiro loladiro
Lab Rat
596 posts

Try using QT_NO_KEYWORDS in files that need that header file.

July 12, 2011

alexandros alexandros
Ant Farmer
114 posts

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

July 12, 2011

loladiro loladiro
Lab Rat
596 posts

I’m sorry, I was kinda in a hastle of getting home when I posted that ;).
What i meant is using

  1. #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!

July 12, 2011

alexandros alexandros
Ant Farmer
114 posts

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:

  1. 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 :/

July 12, 2011

loladiro loladiro
Lab Rat
596 posts

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

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?

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.

July 13, 2011

alexandros alexandros
Ant Farmer
114 posts

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?

July 13, 2011

loladiro loladiro
Lab Rat
596 posts

  1. slots: -> Q_SLOTS:
  2. signals: -> Q_SIGNALS:
  3. emit -> Q_EMIT

http://doc.qt.nokia.com/4.7/qobject.html#Q_SIGNALS

EDIT: fixed, sorry for the confusion

July 13, 2011

alexandros alexandros
Ant Farmer
114 posts

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

July 13, 2011

alexandros alexandros
Ant Farmer
114 posts

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

July 13, 2011

loladiro loladiro
Lab Rat
596 posts

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

September 4, 2011

alexandros alexandros
Ant Farmer
114 posts

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

 
  ‹‹ How to have the TabWidget control from top to bottom approach instead of left to right by default?      Is that possible access default QLineEdit used in QListWidget::editItem() ? ››

You must log in to post a reply. Not a member yet? Register here!