Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUiLoader and QMainWindow.ui

QUiLoader and QMainWindow.ui

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Exotic_Devel
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved