Use QT3 and QT4 instance resolution in Ubuntu

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.