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. Loader generating header
Forum Updated to NodeBB v4.3 + New Features

Loader generating header

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.7k Views 1 Watching
  • 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

    I'm using QUiLoader for some tests, I realize that after compiling, generates the header file (.h) of form.

    If the instantiation is dynamic, why does generating this header?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      Normally you use "UIC":http://qt-project.org/doc/qt-4.8/uic.html to generate a header file (.h) from your Qt Designer file (.ui). This header file is then compiled into your application, which happens at compile time, so the .ui file will not be needed at runtime. Alternatively you can use the QUiLoader class to dynamically generate the user interface from an .ui file at runtime. You would only do the latter, if you really need your application to generate the UI dynamically at runtime...

      (I guess one use case for the QUiLoader class would be an application where you explicitly want the user to be able to modify the UI without re-compiling the application. But normally you just use the standard UIC approach)

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

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

        I am using QUiLoader, but the file (. Uí) is being compiled.

        My code

        @#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();
        

        }
        @

        After compilation, ui_MainWindow.h appears in the directory

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          As explained before, when using the QUiLoader class, the UI is generated directly from the .ui file, at runtime. You don't need a .h file, generated by UIC, in this case. Sure, you can still compile your .ui file into a .h file, using UIC, even when using the QUiLoader class. But it's just redundant & pointless ;-)

          Or the other way around: If you already have compiled your .ui file into a .h file, using UIC, then you can just create your UI the usual way (using the generated header file) and you do not need to use QUiLoader class at all.

          Recommended reading:
          http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            AFAIK, if your ui file is listed in the FORMS variable in your pro file, then uic will be called on it so the header will be generated

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

              [quote author="SGaist" date="1400527319"]Hi,

              AFAIK, if your ui file is listed in the FORMS variable in your pro file, then uic will be called on it so the header will be generated[/quote]

              How to prevent it? editing ".pro"?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MuldeR
                wrote on last edited by
                #7

                [quote author="Exotic_Devel" date="1400531897"][quote author="SGaist" date="1400527319"]Hi,

                AFAIK, if your ui file is listed in the FORMS variable in your pro file, then uic will be called on it so the header will be generated[/quote]

                How to prevent it? editing ".pro"?[/quote]

                Yes. If you don't want your .ui file to be compiled into a header file, you can simply edit the .pro file and remove it from FORMS variable. But may I ask: Why do you want to use the QUiLoader method in the first place?

                bq. FORMS A list of UI files to be processed by uic.

                My OpenSource software at: http://muldersoft.com/

                Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                Go visit the coop: http://youtu.be/Jay...

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

                  For my need, UIC or QUiLoader would function, therefore, my choice is just to test QUiLoader.
                  You have now created an entire application in QUiLoad? What is your opinion?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MuldeR
                    wrote on last edited by
                    #9

                    I have never created an application using QUiLoader, I always use UIC. And I don't see why you would want to use QUiLoader, unless you really need the flexibility to load arbitrary .ui files at runtime. If, however, the .ui file is fixed at compile time, using UIC should give a better performance (the UI XML file doesn't need to be parsed at runtime!). That plus: Using the header file generated by UIC, accessing your individual Widgets is much more convenient. Having to lookup each Widget by its name, as is required with QUiLoader, isn't really nice for non-trivial applications, I assume...

                    @//Using UIC
                    ui->button1->doSomething();

                    //Using QUiLoader
                    QPushButton *button = formWidget->findChild<QPushButton *>("button1");
                    if(button)
                    {
                    button->doSomething();
                    }@

                    My OpenSource software at: http://muldersoft.com/

                    Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                    Go visit the coop: http://youtu.be/Jay...

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

                      Thank you all, sorry my bad english.

                      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