I'm working on an assignment using QT Creator and as a requirement I have to create my GUI without using QT Designer. I have a header file with basically just a constructor. I want to call show my MainWindow in the main.cpp file (and have included my mainwindow.h file) and I have the following code in my main function:
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
I set up my entire gui in my main window.cpp file as follows:
QMainWindow window;
QWidget *widget = new QWidget(&window);
QVBoxLayout *layout = new QVBoxLayout(widget);
...
window.show();
I have tried to maybe use the MainWindow constructor differently in main.cpp file however the GUI only seems to show when I place my Gui code in the main.cpp file instead. I want to separate my GUI so that I don't have to work with a monolith
QT Designer is a tool to create code of widgets.If you use QT Designer create mainwindow.ui. The mainwindow.ui will later be converted to ui_mainwindow.h which is a normal C++ header file.The extra thing you need to do is to implement this header by yourself when you don't have QT Designer.
This is a sample of ui_mainwindow.h auto created from mainwindow.ui.
ui_mainwindow.h
mainwindow.h
mainwindow.cpp
It can be found that you can improve the mainwindow class yourself to achieve the same effect using QT Designer.
main.cpp
mainwindow.h
mainwindow.cpp