Does splitting widgets into multiple ui forms reduces compilation time?
-

What option i should select here? Member pointer?
And then:
// .h #pragma once #include <QtWidgets/QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class MainWindowClass; }; QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindowClass *ui; };
//.cpp #include "stdafx.h" #include "MainWindow.h" #include "ui_MainWindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindowClass()) { ui->setupUi(this); }This way including
ui_MainWindow.hinto the.cpp?@Daniella said in Does splitting widgets into multiple ui forms reduces compilation time?:
it didnt compile
Then please post the compiler error.
The code you posted should work. -
@Daniella said in Does splitting widgets into multiple ui forms reduces compilation time?:
it didnt compile
Then please post the compiler error.
The code you posted should work. -
@jsulm I edited my previous answer, is it 'correct' now? whats the advantage of this 'method'?
@Daniella said in Does splitting widgets into multiple ui forms reduces compilation time?:
whats the advantage of this 'method'?
I already explained what the advantage is. In short: it reduces compile times. You can also google for "C++ forward declaration".
"What option i should select here?" - member pointer. Forward declarations only work with pointers. For non-pointer members the compiler needs to know the type exactly already in the header file.
-
Thank you, i understand now.
Is possible to modify an existing visual studio project to generate the.uias member pointer? -
@jsulm I'm trying to edit it.
Question, how do i access the
uifrom others.cppfiles than themainwindow.cpp?When i try
#include mainwindow.hand tryui->centralWidgeti get this error:"pointer to incomplete class type "Ui::MainWindow" is not allowed -
@jsulm I'm trying to edit it.
Question, how do i access the
uifrom others.cppfiles than themainwindow.cpp?When i try
#include mainwindow.hand tryui->centralWidgeti get this error:"pointer to incomplete class type "Ui::MainWindow" is not allowed@Daniella said in Does splitting widgets into multiple ui forms reduces compilation time?:
Question, how do i access the ui from others .cpp files than the mainwindow.cpp?
You must not - write proper functions to access the ui elements.
-
@Daniella said in Does splitting widgets into multiple ui forms reduces compilation time?:
Question, how do i access the ui from others .cpp files than the mainwindow.cpp?
You must not - write proper functions to access the ui elements.
@Christian-Ehrlicher said in Does splitting widgets into multiple ui forms reduces compilation time?:
write proper functions to access the ui elements.
Could you give an example?
// main.cpp #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); }// mainwindow.h #include <QtWidgets/QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class MainWindowClass; class Form; }; QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); void Test(); Ui::MainWindowClass *ui; Ui::Form *form; };// mainwindow.cpp #include "stdafx.h" #include "MainWindow.h" #include "ui_MainWindow.h" #include "ui_Form.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindowClass()) { ui->setupUi(this); form->setupUi(this); }// test.cpp #include "mainwindow.h" void MainWindow::Test() { ui->centralWidget; // <-- error: "pointer to incomplete class type "Ui::MainWindowClass" is not allowed }how do i access
uiinTest()? -
Hi,
You are missing
#include "ui_MainWindow.h"in your
test.cppfile.Out of curiosity, why are you creating a new file for that method ? You are making your codebase more complex for no benefit.