I have installed C++SDK that have Qt but when I try compiling a code linking QApplication it gives me the error:
Error QApplication: no such file or directory
How do I link these libraries? I searched into the directories and there is a file named QApplication.h; So I tried to link it with -I (linking the directory) but it was still giving me that error.
To start things off, the error
QApplication: no such file or directorymeans your compiler was not able to find this header. It is not related to the linking process as you mentioned in the question.The
-Iflag (uppercase i) is used to specify the include (headers) directory (which is what you need to do), while the-Lflag is used to specify the libraries directory. The-lflag (lowercase L) is used to link your application with a specified library.But you can use Qt to your advantage: Qt has a build system named qmake which makes things easier. For instance, when I want to compile main.cpp I create a main.pro file. For educational purposes, let’s say this source code is a simple project that uses only
QApplicationandQDeclarativeView. An appropriate .pro file would be:Then, execute the
qmakeinside that directory to create the Makefile that will be used to compile your application, and finally executemaketo get the job done.On my system this
makeoutputs:Note: I installed Qt in another directory –>
/opt/qt_47xEdit: Qt 5.x and later
Add
QT += widgetsto the .pro file and solve this problem.