当前位置:网站首页>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;
}
边栏推荐
- Gradle notes
- aaaaaaaaaaaaa
- 在QML中加载不同字体
- Verilog 过程赋值 区别 详解
- Common means of modeling: aggregation
- Framing in data transmission
- 焱融看 | 混合雲時代下,如何制定多雲策略
- "Analysis of 43 cases of MATLAB neural network": Chapter 41 implementation of customized neural network -- personalized modeling and Simulation of neural network
- 跟着CTF-wiki学pwn——ret2shellcode
- halcon图像矫正
猜你喜欢

Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud

Pycharm2021 delete the package warehouse list you added

Learn PWN from CTF wiki - ret2shellcode

Uniapp uses canvas to generate posters and save them locally

One of the future trends of SAP ui5: embrace typescript

只需简单几步 - 开始玩耍微信小程序

Discrimination between sap Hana, s/4hana and SAP BTP

Pointer array & array pointer

JIT deep analysis

Continuous assignment of Verilog procedure
随机推荐
C reflection practice
Kotlin基础学习 15
在QML中加载不同字体
What is hybrid web containers for SAP ui5
Use blocking or non blocking for streamline
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
MSI announced that its motherboard products will cancel all paper accessories
《MATLAB 神经网络43个案例分析》:第42章 并行运算与神经网络——基于CPU/GPU的并行神经网络运算
知物由学 | 自监督学习助力内容风控效果提升
Uniapp uses canvas to generate posters and save them locally
Kotlin基础学习 14
"Analysis of 43 cases of MATLAB neural network": Chapter 42 parallel operation and neural network - parallel neural network operation based on cpu/gpu
Verilog 线型wire 种类
Kotlin basic learning 16
/silicosis/geo/GSE184854_scRNA-seq_mouse_lung_ccr2/GSE184854_RAW/GSM5598265_matrix_inflection_demult
Work hard all day long and be alert at sunset
ThreadLocal详解
[C Advanced] brother Peng takes you to play with strings and memory functions
ORA-01547、ORA-01194、ORA-01110
Review materials of project management PMP high frequency examination sites (8-1)