I started to learn C ++ and didn't know much about many things. On Ubuntu, I learned QT easily, just as I knew MFC easily on Windows. QT is really powerful. I decided to record my learning process for future reference. First, write down my getting started knowledge (content from Ubuntu official wiki.ubuntu.org.cn), "Helloubuntu! ". The first is a simple QT3 program: first create a directory qt3hello, and then create a file
I started to learn C ++ and didn't know much about many things. On Ubuntu, I learned QT easily, just as I knew MFC easily on Windows. QT is really powerful. I decided to record my learning process for future reference. First, write down my getting started knowledge (content from Ubuntu official wiki.ubuntu.org.cn), "Hello ubuntu! ". The first is a simple QT3 program:
First create a directory qt3hello, and then create a file main. cpp in it, the content is as follows:
# Include
# Include
Int main (int argc, char ** argv)
{
QApplication a (argc, argv );
QPushButton hello ("Hello ubuntu! ", 0 );
Hello. resize (100,30 );
A. setMainWidget (& hello );
Hello. show ();
Return a.exe c ();
}
Compile and run the following command:
$ Cd ~ /Qt3hello
$ Qmake-project
$ Qmake
$ Make
$./Qt3hello
This is an example of QT4. The content is also from wiki.ubuntu.org.cn, but the above compilation command is wrong, wasting a lot of time for beginners like me. I corrected it.
First, create the folder qt4hello, and create the file main. cpp. The content is as follows:
# Include
# Include
Int main (int argc, char * argv [])
{
QApplication app (argc, argv );
QPushButtion hello ("Hello Ubuntu! ");
Hello. resize (100,30 );
Hello. show ();
Return app.exe c ();
}
Use the following command to compile
$ Cd ~ /Qt4hello
$ Qmake-qt4-project
$ Qmake-qt4
$ Make
Then run
$./Qt4hello
OK!
The following is a summary of the execution of the QT program. Taking QT3 as an example, QT4 is similar.
The header file qapplication. h contains the definition of QApplaction. All QT programs must be an object of QApplication. QApplication manages many program resources and can monitor the system status in real time to provide feedback to the program.
The header file qpushbutton. h contains the definition of the QPushButton class.
First generate a QApplication object, and then use a. setMainWidget (& hello) to use the QPushButton object as the main window component of the application.
A.exe c (); when the control is handed over to QT, when the program is executed, exec () will return.
At this point, we have understood the most basic things of QT. I believe I will fix it myself.