QUiLoader and QMainWindow.ui



  • In the examples found in the documentation QUiLoader; . the call to the interface through the ui file is done this way:

    @ MainWindow::MainWindow(QWidget *parent):QWidget(parent)
    {
    QUiLoader loader;
    QFile file_ui("Forms/MainWindow.ui");
    file_ui.open(QIODevice::ReadOnly);
    QWidget *mainwindow = loader.load(&file_ui, this);

        QVBoxLayout *layout = new QVBoxLayout();
        layout->addWidget(mainwindow);
        setLayout(layout);
    }
    

    @

    However, I see no logic in putting QMainWindow inside another widget.
    How to run a QMainWindow.ui through QUiLoader?



  • Ok, I put within Main.cpp

    @#include <QApplication>
    #include <QWidget>
    #include <QUiLoader>
    #include <QFile>

    //#include "MainWindow.hpp"

    int main (int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QUiLoader loader;
    QFile file_ui("Forms/MainWindow.ui");
    file_ui.open(QIODevice::ReadOnly);
    QWidget *mainwindow = loader.load(&file_ui);
    mainwindow->show();
    

    /* MainWindow mainwindow;
    mainwindow.show(); */

    return app.exec();
    

    }
    @

    However, I do not know if this is the correct way to do this.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.