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
Make sure you have qmake in your path (which qmake), and that it works (qmake -v) (IF you have to kill it with ctr-c then there is something wrong with your environment).
Then follow this: http://developer.qt.nokia.com/doc/qt-4.8/gettingstartedqt.html
In Qt 5 you now have to add widgets
to the QT
qmake variable (in your MyProject.pro
file).
QT += widgets
You can change build versiyon.For example i tried QT 5.6.1 but it didn't work.Than i tried QT 5.7.0 .So it worked , Good Luck! :)
Looks like you don't have the development libraries installed. Install them using:
sudo apt-get install libqt4-dev
As you said int the comments that you have them installed, just re-install it. Now. to update the locate's database, issue this command $sudo updatedb
Then $locate QApplication
to check that you now have the header file installed.
Now, goto the the folder where you have the code & type these commands
qmake -project
qmake
make
Then you can find the binary created.
Alternatively, you can use Qt Creator if you want the GUI.
See the official documentation for more info. http://developer.qt.nokia.com/doc/qt-4.8/gettingstartedqt.html
To learn how to use Qt Creator, use http://doc.qt.nokia.com/qtcreator-2.2/creator-qml-application.html
Well, It's a bit late for this but I've just started learning Qt and maybe this could help somebody out there:
If you're using Qt Creator then when you've started creating the project you were asked to choose a kit to be used with your project, Let's say you chose Desktop Qt <version-here> MinGW 64-bit
. For Qt 5, If you opened the Qt folder of your installation, you'll find a folder with the version of Qt installed as its name inside it, here you can find the kits you can choose from.
You can go to /PATH/FOR/Qt/mingw<version>_64/include
and here you'll find all the includes you can use in your program, just search for QApplication
and you'll find it inside the folder QtWidgets
, So you can use #include <QtWidgets/QApplication>
since the path starts from the include
folder.
The same goes for other headers if you're stuck with any and for other kits.
Note: "all the includes you can use" doesn't mean these are the only ones you can use, If you include iostream
for example then the compiler will include it from /PATH/FOR/Qt/Tools/mingw<version>_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/iostream