程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Comprehensive practice of Python & c++ mixed call programming -21 explanation of QT environment installation and signal slot mechanism

編輯:Python

author : Empty bad uncle
Blog :https://xuhss.com

The breakfast shop won't be open till night , The people who want to eat have already come !

Rely on the QT Explanation of environment installation and signal slot mechanism

One 、QT Source code and SDK download

http://download.qt.io/archive unreliable
http://download.qt.io Sign up to download

QT Yes 2 Programming methods , One is based on QtCreator, The other is based on Visual Studio. If you are Linux perhaps Mac, You can use it directly QtCreator, If it's in Windows, Recommended VS.

Why not QtCreator, Compared with other development integration environments , You have used in actual development QtCreator You will find it easy to use , But relative to vs He is a younger brother . For example, the project is based on Qmake, It often fails to generate some compilers , There will be some bug, Relatively speaking vs Of bug A lot less , and vs When debugging and configuring third-party libraries , More convenient .

If you use vs Words , Need to download vs-addin:

download.qt.io/archive/vsaddin/

qt It is recommended to download 5.9, It is a long-term maintenance version :

http://download.qt.io/archive/qt

Two 、QT Environmental installation

Double click installation 5.11 edition :

Click Next and select an installation directory :

stay vs Lower development , Check this MSVC:

Sources You can check or uncheck , If checked, you can debug to QT Source code .

The following is the default installation . Agree to the agreement .

3、 ... and 、QT Introduction to installation contents

QT Integrated development environment QTCreator In this way :

D:\Qt\Qt5.9.8\Tools\QtCreator

SDK The path to is at this location :

D:\Qt\Qt5.9.8\5.9.8\msvc2015_64

Four 、Vs-addin install

Double click the installation directly to complete the installation , open vs2015 You can see the menu :

Click on QT Options

You can set :

take sdk Set to 64 position that will do :

5、 ... and 、 Create a FirstQt project

Use Qt GUI Application Create a FirstQt project

Choose what you need to use QT library , The default can be :

Create a main window application , The default can be

After creation , Compile operation :

You can see that a window like this has been created .

Open the main function entry :

#include "FirstQT.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);// The whole application
FirstQT w; // window
w.show(); // Display window
return a.exec(); // Message queuing processing
}

open FirstQT.h

#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_FirstQT.h"
class FirstQT : public QMainWindow // Inherit QMainWindow main window
{
Q_OBJECT
public:
FirstQT(QWidget *parent = Q_NULLPTR);
private:
Ui::FirstQTClass ui;
};

6、 ... and 、QT Add interface control

double-click FirstQT.ui You can open the interface designer .

There are many controls , You can drag a button to the main window , Then use the signal slot to add events to the control :

Add... To the button click Response events :

After the save , Switch to visual studio 2015, Run the program , You can see the control .

Why is it Qt The designer Modified interface , Can be shown in visual studio 2015 What about China? ?

It will be called Uic Program take FirstQt.ui Compile the generated moc_FirstQt.cpp file . This intermediate file automatically generates the interface code .

7、 ... and 、QT The signal slot implements the binding of control events

Came to FirstQt.h Add slot function to Test()

#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_FirstQT.h"
class FirstQT : public QMainWindow // Inherit QMainWindow main window
{
Q_OBJECT
public:
FirstQT(QWidget *parent = Q_NULLPTR);
public slots:
void Test();
private:
Ui::FirstQTClass ui;
};

FirstQt.cpp Add implementation :

#include "FirstQT.h"
#include <iostream>
using namespace std;
FirstQT::FirstQT(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
void FirstQT::Test()
{
cout << "FirstQt::Test()" << endl;
}

Modify the console output to facilitate demonstration :

function :

Share high-quality articles in previous periods

  • C++ QT combination FFmpeg Actual development of video player -01 Environment installation and project deployment
  • solve QT problem : function qmake:Project ERROR: Cannot run compiler ‘cl‘. Output:
  • Resolve installation QT after MSVC2015 64bit No compiler and debugger issues with configuration
  • Qt Kit tips in no complier set in kit and no debugger, The yellow exclamation mark appears and the problem is solved (MSVC2017)
  • Python+selenium automation - Realize automatic import 、 Upload external files ( Don't pop up windows window )

High quality tutorial sharing

  • If you don't enjoy reading the article , You can come to my other special column Take a look ~
  • For example, the following columns :Python Actual wechat ordering applet 、Python Quantitative trading practice 、C++ QT Practical projects and Algorithm learning column
  • You can learn more about C++/Python Relevant contents of ! Directly click on the color font below to jump !
Learning route guidance ( Click unlock ) Knowledge orientation Crowd positioning 🧡 Python Actual wechat ordering applet 🧡 Progressive class This course is python flask+ Perfect combination of wechat applet , From the deployment of Tencent to the launch of the project , Create a full stack ordering system .Python Quantitative trading practice beginner Take you hand in hand to create an easy to expand 、 More secure 、 More efficient Quantitative trading System ️ C++ QT combination FFmpeg Actual development of video player ️ The difficulty is high Sharing learning QT Finished video player source code , We need to have a solid C++ knowledge ! A community of 90000 game lovers Help each other / Blow water 90000 game lovers community , Chat and help each other , White whoring prize Python Zero basis to introduction Python beginner For small partners who have not been systematically studied , The core purpose is to enable us to learn quickly Python Knowledge to get started

Data white whoring , reminder

Follow the card below to get more programming knowledge immediately , Including various language learning materials , Thousands of sets PPT Templates and various game source materials and so on . More information can be viewed by yourself !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved