当前位置:网站首页>UI (New ui:: MainWindow) troubleshooting
UI (New ui:: MainWindow) troubleshooting
2022-07-02 03:26:00 【Never stop】
List of articles
One 、 Problem description
QT Generate a simple MainWindow After the project ,mainwindows.cpp in , Realized MainWindow Constructor for , See the following code .
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
Two lines of code after the colon , yes C++ List initialization of . among QMainWindow(parent) Is to explicitly call the constructor of the base class , ui(new Ui::MainWindow) Is initialization ui The pointer .ui Pointer in mainwindow.h As defined in .
I saw ui(new Ui::MainWindow) , Here comes my question ,MainWindow Constructor for , Meeting new One MainWindow, No, I will call again MainWindow Constructor of ? This is not a set of dolls ? It's going to cycle . But the actual operation is normal , It must be my own misunderstanding .
Conclusion :
QT Name two different classes MainWindow, adopt namespace It makes a distinction .
Ui Variable name of namespace , And the variable name of the default space , Although the same , But there are actually two things .
Two 、 Problem analysis
1.mainwindow.h
See the notes of the code
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow_gui; // The original MainWindow Change it to MainWindow_gui. Here in “Ui” In the namespace of , Declared a MainWindow_gui class .
}
class MainWindow : public QMainWindow // MainWindow Is based on QMainWindow Derived classes
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
// Defined a point MainWindow_gui The pointer to pui.MainWindow_gui Is in Ui In namespace , So write it as “ Ui::MainWindow_gui”
Ui::MainWindow_gui * pui;
};
#endif // MAINWINDOW_H
2.ui_mainwindow.h
This file , Not under the project directory , Should be qt After generation, it is placed in the compilation directory . Compile time will connect .
See the notes of the code
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
// *** Omit ***
class Ui_MainWindow // Defined a Ui_MainWindow class
{
public:
// *** Omit ***
void setupUi(QMainWindow *MainWindow)
{
// *** Omit ***
} // setupUi
};
namespace Ui {
// Ui In space , Defined a MainWindow_gui class , This class inherits from Ui_MainWindow
class MainWindow_gui: public Ui_MainWindow {
};
} // namespace Ui
#endif // UI_MAINWINDOW_H
3.mainwindow.cpp
This file , Not under the project directory , Should be qt After generation, it is placed in the compilation directory . Compile time will connect .
See the notes of the code
// Manual test , There is no order between the two header files include The relationship between
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : // The concrete realization of MainWindow Constructor for
QMainWindow(parent), // Call the base class QMainWindow Constructor for , because MainWindow It's from QMainWindow Derived from
pui(new Ui::MainWindow_gui) // new One Ui In space MainWindow_gui class , And initialize its pointer pui
{
pui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete pui;
}
边栏推荐
- tarjan2
- < job search> process and signal
- 知物由学 | 自监督学习助力内容风控效果提升
- C shallow copy and deep copy
- GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
- [JS reverse series] analysis of a customs publicity platform
- Verilog timing control
- Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
- venn图取交集
- Uniapp uses canvas to generate posters and save them locally
猜你喜欢
Knowing things by learning | self supervised learning helps improve the effect of content risk control
This article describes the step-by-step process of starting the NFT platform project
Just a few simple steps - start playing wechat applet
[golang] leetcode intermediate bracket generation & Full Permutation
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
Halcon image rectification
Continuous assignment of Verilog procedure
跟着CTF-wiki学pwn——ret2shellcode
[JS reverse series] analysis of a customs publicity platform
数据传输中的成帧
随机推荐
C#聯合halcon脫離halcon環境以及各種報錯解决經曆
Qt的网络连接方式
Verilog 状态机
Spark Tuning
数据传输中的成帧
This article describes the step-by-step process of starting the NFT platform project
"Analysis of 43 cases of MATLAB neural network": Chapter 42 parallel operation and neural network - parallel neural network operation based on cpu/gpu
Form custom verification rules
Aaaaaaaaaaaa
Apple added the first iPad with lightning interface to the list of retro products
竞争与冒险 毛刺
Kotlin basic learning 14
In the era of programmers' introspection, five-year-old programmers are afraid to go out for interviews
Kotlin basic learning 15
3124. Word list
h5中的页面显示隐藏执行事件
C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
Knowing things by learning | self supervised learning helps improve the effect of content risk control
Custom classloader that breaks parental delegation
SAML2.0 notes (I)