Install and use the Qt5 framework in Win7

Source: Internet
Author: User

1. Install Qt5

Integration with MinGW and Qt Creator. You do not need to download MinGW and Qt Creator separately.

First, go to the Qt official website to download resources: qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe; then, double-click to install. After the installation, the "Start" menu is shown as follows:

2. Configure Qt

Open Qt Creator, tool --> option, and open the "options" dialog box, as shown in the following figure:

If no result is detected, add the corresponding Qt version and compiler (MinGW), and then set the build kit (Kits): Device Type, compiler (MinGW), debugger, and Qt version, as shown in the following figure.

3. Use Qt

Open Qt Creator, create a project --> other projects --> empty qmake project, name the project "QtTest", and add the new file main. cpp.

Add the following code to main. cpp:

 

The code is as follows: Copy code

# Include <QApplication>
# Include <QVBoxLayout>
# Include <QLabel>
# Include <QPushButton>

Int main (int argc, char * argv [])
{
QApplication app (argc, argv );

QWidget * window = new QWidget;
Window-> setWindowTitle ("QtTest ");

// QLabel * label = new QLabel ("Hello Qt ");
QLabel * label = new QLabel ("

QPushButton * button = new QPushButton ("Quit ");
QObject: connect (button, SIGNAL (clicked (), & app, SLOT (quit ()));

QVBoxLayout * layout = new QVBoxLayout;
Layout-> addWidget (label );
Layout-> addWidget (button );
Window-> setLayout (layout );

Window-> show ();

Return app.exe c ();
}

 

 

The code displays the following error:

Runtime error prompt: # include -- No such file ......

In fact, many common QT header files in QT5 are moved to modules such as core gui widgets. In QT5, an additional line is required for the. pro File (case sensitive ):

QT + = core gui widgets

Qt + = core gui widgets indicates the link QtCore (d). dll, QtGui (d). dll, and QtWidgets (d). dll.

Add a line of the above code to the. pro file, save the code, and double-click the. cpp file. The error message line disappears and runs, as shown in the following figure:

Note:

1. Qt supports simple Html style formats.

2. MinGW provides a simple and convenient GCC-based development environment in Windows. MinGW collects a series of free Windows header files and library files. It also integrates the GNU tool set, especially the GNU program development tools, such as the classic gcc, g ++, and make. MinGW is a free software. It simulates the GCC development environment in Linux on the Windows platform and provides a good foundation for cross-platform development of C ++, in order to familiarize programmers working in Windows with the C ++ engineering organization in Linux, the conditions are provided.

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.