Here is a test example, I create a Form class and work with its ui in mainwindow. I guess this is a bad way, but affordable. How to interact with ui? Via get / set? through signals and slots? leave such test cases, I will be grateful.

form.h

#ifndef FORM_H #define FORM_H #include <QWidget> namespace Ui { class Form; } class Form : public QWidget { Q_OBJECT public: explicit Form(QWidget *parent = 0); ~Form(); //private: Ui::Form *ui; }; #endif // FORM_H 

form.cpp

 #include "form.h" #include "ui_form.h" Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form) { ui->setupUi(this); } Form::~Form() { delete ui; } 

mainwindow.h

 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "form.h" namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; Form *form; }; #endif // MAINWINDOW_H 

mainwindow.cpp

 #include "mainwindow.h" #include "ui_mainwindow.h" #include "ui_form.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); form = new Form(); form->ui->lineEdit->setText("Qt"); connect(this->ui->actionForm, SIGNAL(triggered()), form, SLOT(show())); } MainWindow::~MainWindow() { delete ui; } 
  • one
    As a rule, it is not necessary to interact with the ui of another class. For example, your Form window is intended for some kind of action (asking the user for some information or notifying the user about something). Declare in Form the signals / slots / properties associated with these actions, and not with the structure of the editor. - Chorkov
  • It depends on what the Form is for. Perhaps you should read about modal \ non-modal windows and how to call them correctly. For example, here: itnotesblog.ru/note.php?id=230 . In any case, it’s probably wrong to create a Form object in the constructor; it’s better to do it through a slot at the triggered () signal, like you do. - bronstein87

0