这个文件是使用UIC工具对.ui文件进行处理获得的,如果不自己手动进行,但是开启了CMake的AUTOUIC功能的话,编译时也会对其进行处理,但可能会保存在 cmake-build-debug/[executable_name]_autogen/include 目录下

/********************************************************************************
** Form generated from reading UI file 'my_qt_dialog_second.ui'
**
** Created by: Qt User Interface Compiler version 5.15.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_MY_QT_DIALOG_SECOND_H
#define UI_MY_QT_DIALOG_SECOND_H

#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>

namespace MyQtSecond {

class Ui_MyQtDialogSecond
{
public:

    void setupUi(QDialog *MyQtSecond__MyQtDialogSecond)
    {
        if (MyQtSecond__MyQtDialogSecond->objectName().isEmpty())
            MyQtSecond__MyQtDialogSecond->setObjectName(QString::fromUtf8("MyQtSecond__MyQtDialogSecond"));
        MyQtSecond__MyQtDialogSecond->resize(320, 195);

        retranslateUi(MyQtSecond__MyQtDialogSecond);

        QMetaObject::connectSlotsByName(MyQtSecond__MyQtDialogSecond);
    } // setupUi

    void retranslateUi(QDialog *MyQtSecond__MyQtDialogSecond)
    {
        MyQtSecond__MyQtDialogSecond->setWindowTitle(QCoreApplication::translate("MyQtSecond::MyQtDialogSecond", "MyQtDialogSecond", nullptr));
    } // retranslateUi

};

} // namespace MyQtSecond

namespace MyQtSecond {
namespace Ui {
    class MyQtDialogSecond: public Ui_MyQtDialogSecond {};
} // namespace Ui
} // namespace MyQtSecond

#endif // UI_MY_QT_DIALOG_SECOND_H

它做将会做以下工作:定义了类Ui_MyQtDialogSecond用来封装可视化界面,自动生成各个组件的成员变量定义(这份文件没有),定义setupUI函数,用来创建哥哥界面组件,并设置其位置,大小,文字,字体等属性,以及也会有信号与槽的关联(如果ui中定义过的话)

最后为了让外部的文件可以使用,特意在Ui命名空间定义了一个同名的MyQtDialogSecond继承自Ui_MyQtDialogSecond。虽然在my_qt_dialog_second.h 文件中看到的Ui::MyQtDialogSecond和在其中定义的MyQtDialogSecond是两个类,但是Qt的处理可以让用户感觉不到Ui::MyQtDialogSecond的存在,只需要知道在MyQtDialogSecond中使用ui→指针就可以访问可视化设计的界面组件就好了

为什么要这样做呢?

也许是为了提高编程的体验,除此之外也能让修改控件位置甚至数量的时候需要重新编译的文件数量降到最低(只需要重编译ui_**.h即可,否则所有文件都可能会编译一遍)

QT namespace UI_hebbely的博客-CSDN博客_namespace qt