在Qt中setupUi(this)有什么用?

Aks*_*ara 10 qt

我是Qt的新手.我从网上下载了一个来源.

头文件包含以下内容

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

       ainWindow>

namespace Ui {
   class MainWindow;
}

class MainWindow : public QMainWindow
{
      Q_OBJECT
      public:
         explicit MainWindow(QWidget *parent = 0);
         ~MainWindow();

      private:
         Ui::MainWindow *ui; // Need for this line. Any one please help
};

#endif // MAINWINDOW_H
Run Code Online (Sandbox Code Playgroud)

在mainwindow.cpp文件中,ui-> setupUI(this)已在构造函数中调用.请帮助创建ui变量的必要性

Tim*_*yer 6

您需要一个MainWindow.ui文件,然后由Qt的UIC机制处理,如果您运行qmake,则会触发该机制.

如果您使用带有Qt插件或Qt Creator的Visual Studio这样的IDE,只需通过向导创建一个新的Qt GUI类,您将拥有所需的一切.

本页深入讨论了UI文件的用法.