Basic question: Including headers with INCLUDEPATH doesn't work
-
No, it works that way. pr default. Nothing I have seen in Creator adjust that.
Only thing that can go wrong is path is invalid ( on windows, spaces in path can be issue)HEADERS += libA.h
Will work if the libA.h is in the same folder as the .pro file
Else its FALSE and will not work. -
No, it works that way. pr default. Nothing I have seen in Creator adjust that.
Only thing that can go wrong is path is invalid ( on windows, spaces in path can be issue)HEADERS += libA.h
Will work if the libA.h is in the same folder as the .pro file
Else its FALSE and will not work.@mrjj
I found out that the problem only appears to a few header files!I include 3 headers, each declaring a subclass of a standard Qt class:
INCLUDEPATH += C:/Qt/lib/headers HEADERS += main.h SOURCES += main.cpp \ myQLineEdit.cpp \ myQPushButton.cpp \ myQString.cpp
The errors appear to the functions defined in the source files myQLineEdit.cpp and myQPushButton.cpp, but NOT in myQString.cpp!
I think I got the problem!! In myQLineEdit and myQPushButton class, I do have a Q_OBJECT. Can this cause the problems??
-
Q_OBJECT is used by a tool called moc.exe to help make signals and slot possible
It should not to anything with regards to include files. :)
As far as I have ever seen. -
By the way:
the problem really is Q_OBJECT...I just wrote "Q_OBJECT" into the myQString class and look what happened: undefined reference vtable ... in myQString.cpp!
So Q_OBJECT makes the problems why I have to add all headers to the project! How can I avoid this?
-
when u add Q_OBJECT, please run qmake!
-
I already tried that.
Building, running
Building, qmake, running
qmake, running
qmake, building, runningNone of the above ways succeded
-
tried that, two.
Deleted everything but my project file and the sources/headers. Didn't work :-(
Is it possible that qmake ignores INCLUDEPATH?
-
Well, I'll post the whole project file, its headers and sources and maybe you can copy/paste it and try to run it with?
If it works, then it is a setting problem. If not, something with my include logic doesn't work.
project file:
#------------------------------------------------- # # Project created by QtCreator 2016-11-17T15:45:17 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = CourseCalculator TEMPLATE = app INCLUDEPATH += C:/Qt/lib/headers HEADERS += main.h SOURCES += main.cpp C:/Qt/lib/sources/myQString.cpp \ C:/Qt/lib/sources/myQLineEdit.cpp \ C:/Qt/lib/sources/myQPushButton.cpp
main.cpp:
// main.cpp #include "main.h" int main(int argc, char *argv[]) { QApplication applicationApp(argc, argv); clsWindowMain windowMain; QTimer::singleShot(0, &windowMain, SLOT(slotStart())); int ret = applicationApp.exec(); return ret; } main.h:
// main.h
#ifndef MAIN_H #define MAIN_H #include <QApplication> #include <QTimer> #include <QWidget> #include <QDialog> #endif // MAIN_H
myQLineEdit.h:
// myQLineEdit.h #ifndef MYQLINEEDIT_H #define MYQLINEEDIT_H #include <QDebug> #include <QLineEdit> #include <QMessageBox> #include <QDir> // forward declaration class myQLineEdit; // declaration class myQLineEdit : public QLineEdit { Q_OBJECT // .. properties public: myQLineEdit(QWidget* widgetParent = 0); ~myQLineEdit(); // .. more methods }; #endif
myQLineEdit.cpp:
// myQLineEdit.cpp #include <myQLineEdit.h> // absolute path or absolute path with whitespaces also doesn't work // ----- constructors ----- myQLineEdit::myQLineEdit(QWidget* widgetParent) : QLineEdit(widgetParent) { // stuff }
Is that compilable for you?
-
Well, I'll post the whole project file, its headers and sources and maybe you can copy/paste it and try to run it with?
If it works, then it is a setting problem. If not, something with my include logic doesn't work.
project file:
#------------------------------------------------- # # Project created by QtCreator 2016-11-17T15:45:17 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = CourseCalculator TEMPLATE = app INCLUDEPATH += C:/Qt/lib/headers HEADERS += main.h SOURCES += main.cpp C:/Qt/lib/sources/myQString.cpp \ C:/Qt/lib/sources/myQLineEdit.cpp \ C:/Qt/lib/sources/myQPushButton.cpp
main.cpp:
// main.cpp #include "main.h" int main(int argc, char *argv[]) { QApplication applicationApp(argc, argv); clsWindowMain windowMain; QTimer::singleShot(0, &windowMain, SLOT(slotStart())); int ret = applicationApp.exec(); return ret; } main.h:
// main.h
#ifndef MAIN_H #define MAIN_H #include <QApplication> #include <QTimer> #include <QWidget> #include <QDialog> #endif // MAIN_H
myQLineEdit.h:
// myQLineEdit.h #ifndef MYQLINEEDIT_H #define MYQLINEEDIT_H #include <QDebug> #include <QLineEdit> #include <QMessageBox> #include <QDir> // forward declaration class myQLineEdit; // declaration class myQLineEdit : public QLineEdit { Q_OBJECT // .. properties public: myQLineEdit(QWidget* widgetParent = 0); ~myQLineEdit(); // .. more methods }; #endif
myQLineEdit.cpp:
// myQLineEdit.cpp #include <myQLineEdit.h> // absolute path or absolute path with whitespaces also doesn't work // ----- constructors ----- myQLineEdit::myQLineEdit(QWidget* widgetParent) : QLineEdit(widgetParent) { // stuff }
Is that compilable for you?
-
Good idea. But my dropbox accout has no free memory left :-D
Have to create a new account first, maybe on g drive...
-
Good idea. But my dropbox accout has no free memory left :-D
Have to create a new account first, maybe on g drive...
-
but from where do I get this moc file?
If I try to include, compiler gives me an error that it can not find such file or directorybtw:
https://www.dropbox.com/s/whqdkcat767224t/test.zip?dl=0 -
but from where do I get this moc file?
If I try to include, compiler gives me an error that it can not find such file or directorybtw:
https://www.dropbox.com/s/whqdkcat767224t/test.zip?dl=0 -
but from where do I get this moc file?
If I try to include, compiler gives me an error that it can not find such file or directorybtw:
https://www.dropbox.com/s/whqdkcat767224t/test.zip?dl=0 -
but from where do I get this moc file?
If I try to include, compiler gives me an error that it can not find such file or directorybtw:
https://www.dropbox.com/s/whqdkcat767224t/test.zip?dl=0 -
@jsulm , why would you include the MOC files? I "never" include the MOC files in my source because they get generated, compiled, and linked after the normal build. The only generated file I would include is the ui_NameOfForm.h file created when using the form designer. And, only in the CPP for the UI class.
@Binary91 , I am sure it was explained that INCLUDEPATH tells qmake where to find common include files. I use it for 3rd party libraries or pre-built packages I developed for Qt (I treat them like 3rd party libraries). And, as I know you know... always run qmake after changing a PRO file.
There is one curious item I have found about QtCreator though... if you are using static libraries (even if your dependencies are setup) and make a change to a CPP file in the library... Press build-all and it will build the library and NOT re-link the application or shared library that depends on that static library. Kind of annoying but I just get around it!