Installation and use of QT5 under Win7

Source: Internet
Author: User

1, installation Qt5  

The installation of QT5 is much simpler than the installation of QT4, and I am loaded with Qt5.4(qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe), which integrates MinGW, QT Creator, etc., does not require you to download MinGW and QT Creator separately.

First, go to QT official website download resources: Qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe; Then, double-click Install. After installation, the Start menu:

2. Configure QT

Open the QT Creator, tools-and options, open the Options dialog box, as shown in:

If not detected, add the appropriate QT version and compiler (MinGW), and then set the build Kit (Kits): Device type, compiler (MinGW), debugger, QT version as shown in.

3. Using QT

Open QT Creator, new project---other projects-- empty Qmake project , project named "Qttest", add new file main.cpp.

Add the following code to the main.cpp:

#include <QApplication>#include<QVBoxLayout>#include<QLabel>#include<QPushButton>intMainintargcChar*argv[])    {qapplication app (ARGC,ARGV); Qwidget*window =NewQwidget; Window->setwindowtitle ("qttest"); //Qlabel *label= New Qlabel ("Hello Qt");Qlabel *label =NewQlabel ("""<font color = red>qt</font>"); Qpushbutton*button=NewQpushbutton ("Quit"); Qobject::connect (Button,signal (clicked ()),&App,slot (Quit ())); Qvboxlayout*layout=Newqvboxlayout; Layout-addwidget (label); Layout-addwidget (button); Window-setlayout (layout); Window-Show (); returnapp.exec ();}

At this point, the code displays the following error:

Run-time error prompt: #include <qapplication>--no such file ...

In fact,many of the common Qt header files in QT5 are moved to modules such as the core GUI widgets , and in QT5, the. Pro file needs to add an additional line (note case):

QT + + Core GUI widgets

where Qt + + Core GUI widgets represents link Qtcore (d). dll, Qtgui (d). dll, Qtwidgets (d). dll.

We add a line of the above code in the. Pro file, save, and then double-click to open the. cpp file, at which point the error line disappears and runs, as shown in the results:

Note:

1.QT supports a simple Html style format .

2,MinGW provides a set of simple and convenient based on the GCC program development environment under Windows . MinGW collects a series of free Windows-used header files and library files, and integrates the GNU toolset, especially GNU program development tools such as classic GCC, g++, make, etc. MinGW is free software, which simulates the development environment of the Linux under GCC on the Windows platform , provides a good foundation for C + + cross-platform development, and is familiar with C + + under Linux for programmers working under Windows. The engineering organization provided the conditions.

Installation and use of QT5 under Win7

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.