In the root directory, create a folder named Hello, under which a hello.cpp file is created with the following contents:
#include <QApplication> #include <qlabel>int main (int argc, char **argv) {qapplication A (argc, argv); Qlabel MyLabel ("Hello the World"); Mylabel.show (); return a.exec ();}
Run the following command under the file:
Qmake-project
This command generates a Hello.pro project file
Qmake
This command generates a makefile file
Make
This command is used to generate the target file: hello,hello.o file
However, you encounter an error in this process:
g++-c-pipe-o2-wall-w-d_reentrant-dqt_no_debug-dqt_gui_lib-dqt_core_lib-i/usr/share/qt4/mkspecs/linux-g++-I.-I/ Usr/include/qt4/qtcore-i/usr/include/qt4/qtgui-i/usr/include/qt4-i.-I.-O hello.o hello.cpp
Hello.cpp:1:24:fatal error:QApplication:No such file or directory
#include <QApplication>
^
Compilation terminated.
Make: * * * [hello.o] Error 1
Cause: No development package for QT4 installed
Solution:
Put the development package on, use the following command under Ubuntu: sudo apt-get install Libqt4-dev
Run the make command now to generate the hello,hello.o file.
Run the./hello command in this directory to run the generated program.
Error "Qapplication:no such file or directory" when running program in QT