Tuesday, July 31, 2007

The first Qt program, hello.cpp

After install MinGW and Qt For Windows, we can creat our first Qt application now.

- Involve "Qt 4.3.0 Command Prompt" from Windows menu.
- Create sub-folder to hold your work if you want. And change to your works folder.
- Create a file "hello.cpp" with the following contents:


#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}


- To create platform-independent project file (hello.pro), type
qmake -project

- To create platform-specific makefile from the project file, type
qmake hello.pro

- Finally build the program, type
make

- Run the generated program, change to the sub-folder "release", and run the program by type
hello