当前位置:网站首页>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;
}
边栏推荐
- Kubernetes cluster storageclass persistent storage resource core concept and use
- Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
- JDBC details
- "Analysis of 43 cases of MATLAB neural network": Chapter 42 parallel operation and neural network - parallel neural network operation based on cpu/gpu
- Knowing things by learning | self supervised learning helps improve the effect of content risk control
- Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
- MSI announced that its motherboard products will cancel all paper accessories
- Verilog 时序控制
- C#聯合halcon脫離halcon環境以及各種報錯解决經曆
- West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
猜你喜欢
Form custom verification rules
Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
MySQL advanced (Advanced) SQL statement (II)
Detailed explanation of the difference between Verilog process assignment
verilog 并行块实现
C shallow copy and deep copy
Verilog parallel block implementation
Halcon image rectification
Verilog avoid latch
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]
随机推荐
JS <2>
PY3 link MySQL
Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
Docker installs canal and MySQL for simple testing and implementation of redis and MySQL cache consistency
ZABBIX API creates hosts in batches according to the host information in Excel files
MSI announced that its motherboard products will cancel all paper accessories
Screenshot literacy tool download and use
[golang] leetcode intermediate bracket generation & Full Permutation
Global and Chinese market of autotransfusion bags 2022-2028: Research Report on technology, participants, trends, market size and share
Mathematical calculation in real mode addressing
《MATLAB 神经网络43个案例分析》:第42章 并行运算与神经网络——基于CPU/GPU的并行神经网络运算
Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]
Qt的网络连接方式
Global and Chinese market of X-ray detectors 2022-2028: Research Report on technology, participants, trends, market size and share
Intersection vengraph
Qualcomm platform WiFi -- Native crash caused by WiFi
Knowing things by learning | self supervised learning helps improve the effect of content risk control
/silicosis/geo/GSE184854_scRNA-seq_mouse_lung_ccr2/GSE184854_RAW/GSM5598265_matrix_inflection_demult