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.