Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to build widgets from any .ui files created by QtDesigner



  • Hi guys,

    I would like to make something like GUI creator which takes an ui file and creates widgets in it, and show in a window.
    So I have created a button on click I use QFileDialog to get a file.
    And then I would like to use the ui file from QFileDialog to create that gui/widgets and show in a window.

    I have tried QFormbuilder, but it always gives me compile error "undefined reference to `QFormBuilder::QFormBuilder()'"

    Is there a way to do it in qt5?

    Any help appreciated


  • Moderators

    Undefined reference sounds like just missing linker lib. Can you show any code (.pro settings)? You're probably missing something like Qt += widgets or whatever the module the QFormBuilder is in.



  • Hi Chris,

    Here is my code.
    @
    void MainWindow::load()
    {
    QString fname = QFileDialog::getOpenFileName(this, tr("Load file ..."),QDir::currentPath(),tr("UI Files (*.ui)"));
    ui->path->setText(fname);

    QFormBuilder loader;
         QFile file("untitled.ui");
         file.open(QFile::ReadOnly);
         QWidget *myWidget = loader.load(&file, this);
         file.close();
    
         QVBoxLayout *layout = new QVBoxLayout;
         layout->addWidget(myWidget);
         setLayout(layout);
    
    
    QMainWindow *mnw = new QMainWindow();
    mnw->setCentralWidget(myWidget);
    mnw->show();
    

    }
    @
    I also wanted it to take the file that is loaded by QFileDialog, but it gives also error.

    Any idea what is wrong?



  • Hi,

    I have solved it by adding designer into my .pro file.

    Thanks anyway.


Log in to reply