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. How to convert .ui to .h?
Forum Updated to NodeBB v4.3 + New Features

How to convert .ui to .h?

Scheduled Pinned Locked Moved Solved General and Desktop
c++ qtconversion
19 Posts 5 Posters 2.7k Views 4 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.
  • S StudentScripter

    @sierdzio i know this method but is there a way to convert the form completely to code after creating it so i don't have to go over ui-> all the time. Also i want to see the layout structure i created and so on in my code. Is there a way with form?

    Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #10

    @StudentScripter said in How to convert .ui to .h?:

    . Also i want to see the layout structure i created and so on in my code. Is there a way with form?

    You see them, in the generated header. What else is needed? If you want to do everything by yourself then simply don't use ui files.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    S 1 Reply Last reply
    2
    • Christian EhrlicherC Christian Ehrlicher

      @StudentScripter said in How to convert .ui to .h?:

      . Also i want to see the layout structure i created and so on in my code. Is there a way with form?

      You see them, in the generated header. What else is needed? If you want to do everything by yourself then simply don't use ui files.

      S Offline
      S Offline
      StudentScripter
      wrote on last edited by
      #11

      @Christian-Ehrlicher I don't see them in the generated headder. I can access the form by ui->pushbutton usw.

      but i don't see it in the headder.

      #ifndef DIALOG_H
      #define DIALOG_H
      
      #include <QDialog>
      
      namespace Ui {
      class Dialog;
      }
      
      class Dialog : public QDialog
      {
          Q_OBJECT
      
      public:
          explicit Dialog(QWidget *parent = nullptr);
          ~Dialog();
      
      private:
          Ui::Dialog *ui;
      };
      
      #endif // DIALOG_H
      
      
      #include "dialog.h"
      #include "ui_dialog.h"
      
      Dialog::Dialog(QWidget *parent)
          : QDialog(parent)
          , ui(new Ui::Dialog)
      {
          ui->setupUi(this);
      }
      
      Dialog::~Dialog()
      {
          delete ui;
      }
      
      

      cd8a8662-7ad4-4e11-a6a6-015a6fada3d2-image.png

      Sorry if we're talking past each other.

      JonBJ Pl45m4P 2 Replies Last reply
      0
      • S StudentScripter

        @sierdzio i know this method but is there a way to convert the form completely to code after creating it so i don't have to go over ui-> all the time. Also i want to see the layout structure i created and so on in my code. Is there a way with form?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #12

        @StudentScripter said in How to convert .ui to .h?:

        Also i want to see the layout structure i created and so on in my code. Is there a way with form?

        As already mentioned by the others, it makes no sense.

        You seem to misunderstand the purpose of the whole QtDesigner/Form-Editor/UI-File stuff...

        It is used to not write too much GUI related code or at least simplify the GUI creation/design process.
        If you decide to use any *.ui file, you have to deal with the fact that "product" which uic outputs is somewhat static.
        Of course you can add or remove stuff by using the pointer to the generated Form class in your actual code. This is recommended and nothing special, but if you do it in the generated header file directy and try to "inject" changes there, every time you re-compile your program (assuming you also re-run uic) everything in your "Form" header will be overridden since it solely generates the header from the XML style definitions in *.ui.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • S StudentScripter

          @Christian-Ehrlicher I don't see them in the generated headder. I can access the form by ui->pushbutton usw.

          but i don't see it in the headder.

          #ifndef DIALOG_H
          #define DIALOG_H
          
          #include <QDialog>
          
          namespace Ui {
          class Dialog;
          }
          
          class Dialog : public QDialog
          {
              Q_OBJECT
          
          public:
              explicit Dialog(QWidget *parent = nullptr);
              ~Dialog();
          
          private:
              Ui::Dialog *ui;
          };
          
          #endif // DIALOG_H
          
          
          #include "dialog.h"
          #include "ui_dialog.h"
          
          Dialog::Dialog(QWidget *parent)
              : QDialog(parent)
              , ui(new Ui::Dialog)
          {
              ui->setupUi(this);
          }
          
          Dialog::~Dialog()
          {
              delete ui;
          }
          
          

          cd8a8662-7ad4-4e11-a6a6-015a6fada3d2-image.png

          Sorry if we're talking past each other.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #13

          @StudentScripter
          You do see everything from your .ui being processed by uic. It is the ui_dialog.h you have included which contains that. That is all uic generates (and you will find it in your build output directory, not your source directory), no .cpp file. And it makes it so all the widgets you designed live in the Ui namespace. You should welcome that and stick with it, not attempt to change it.

          And btw: what that means is you will have two classes named Dialog: one is the plain Dialog you are creating in your own .cpp & .h files, where you can write whatever code you like. The generated ui_....h file also contains a class name Dialog but it is in the Ui namespace. And the class member ui variable is an instance of that. Whose members (your widgets) are accessed via ui->..., so they do not interfere with anything you write in your Dialog class.

          Have a look at the generated ui_dialog.h file and everything should become clear. Note that I have told you above which directory that is in.

          1 Reply Last reply
          1
          • S StudentScripter

            @Christian-Ehrlicher I don't see them in the generated headder. I can access the form by ui->pushbutton usw.

            but i don't see it in the headder.

            #ifndef DIALOG_H
            #define DIALOG_H
            
            #include <QDialog>
            
            namespace Ui {
            class Dialog;
            }
            
            class Dialog : public QDialog
            {
                Q_OBJECT
            
            public:
                explicit Dialog(QWidget *parent = nullptr);
                ~Dialog();
            
            private:
                Ui::Dialog *ui;
            };
            
            #endif // DIALOG_H
            
            
            #include "dialog.h"
            #include "ui_dialog.h"
            
            Dialog::Dialog(QWidget *parent)
                : QDialog(parent)
                , ui(new Ui::Dialog)
            {
                ui->setupUi(this);
            }
            
            Dialog::~Dialog()
            {
                delete ui;
            }
            
            

            cd8a8662-7ad4-4e11-a6a6-015a6fada3d2-image.png

            Sorry if we're talking past each other.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #14

            @StudentScripter said in How to convert .ui to .h?:

            but i don't see it in the headder.

            Because you are looking at the wrong header...
            If you want to see your ui->pushbutton in "code", open the ui_dialog.h and have a look, but you should not modify it there.

            Edit:
            @JonB just modified his post and said what you need to know about the ui pointer and the header...

            I still don't understand why you think you need to do something like this... What's wrong with using the ui-> pointer to access your generated GUI class? Or just do everything in code and don't use any *.ui file at all.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            S 1 Reply Last reply
            1
            • Pl45m4P Pl45m4

              @StudentScripter said in How to convert .ui to .h?:

              but i don't see it in the headder.

              Because you are looking at the wrong header...
              If you want to see your ui->pushbutton in "code", open the ui_dialog.h and have a look, but you should not modify it there.

              Edit:
              @JonB just modified his post and said what you need to know about the ui pointer and the header...

              I still don't understand why you think you need to do something like this... What's wrong with using the ui-> pointer to access your generated GUI class? Or just do everything in code and don't use any *.ui file at all.

              S Offline
              S Offline
              StudentScripter
              wrote on last edited by
              #15

              @Pl45m4 Well my idea was: sometimes it's easier to just prototype a quick layout using the form, but for project organisation and total overview of whats going on i like to have everything in code, so when reading the code i directly see which and how many layouts where used.

              But before i forget thanks you all for your input. I guess i just stick with writing everything in code in this case.

              Christian EhrlicherC JonBJ 2 Replies Last reply
              0
              • S StudentScripter

                @Pl45m4 Well my idea was: sometimes it's easier to just prototype a quick layout using the form, but for project organisation and total overview of whats going on i like to have everything in code, so when reading the code i directly see which and how many layouts where used.

                But before i forget thanks you all for your input. I guess i just stick with writing everything in code in this case.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #16

                Then simply copy the stuff from setupUi() over to your ctor.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • S StudentScripter

                  @Pl45m4 Well my idea was: sometimes it's easier to just prototype a quick layout using the form, but for project organisation and total overview of whats going on i like to have everything in code, so when reading the code i directly see which and how many layouts where used.

                  But before i forget thanks you all for your input. I guess i just stick with writing everything in code in this case.

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #17

                  @StudentScripter
                  Like I said, don't forget it's perfectly possible to look inside the ui_....h file to understand/work with it, just like your own code. You can open it inside Creator, and I imagine (can't remember the key press, maybe F2 does it?) directly from the #include "ui_dialog.h" line. So you really do have the source code there while you're developing. Just don't change anything that is in that file!

                  S 1 Reply Last reply
                  1
                  • JonBJ JonB

                    @StudentScripter
                    Like I said, don't forget it's perfectly possible to look inside the ui_....h file to understand/work with it, just like your own code. You can open it inside Creator, and I imagine (can't remember the key press, maybe F2 does it?) directly from the #include "ui_dialog.h" line. So you really do have the source code there while you're developing. Just don't change anything that is in that file!

                    S Offline
                    S Offline
                    StudentScripter
                    wrote on last edited by
                    #18

                    @JonB Ok thanks well guess i can go in there and just copy what i need after beeing finished with prototyping and than delete the .ui file. :D Thanks man.

                    JonBJ 1 Reply Last reply
                    0
                    • S StudentScripter has marked this topic as solved on
                    • S StudentScripter

                      @JonB Ok thanks well guess i can go in there and just copy what i need after beeing finished with prototyping and than delete the .ui file. :D Thanks man.

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by JonB
                      #19

                      @StudentScripter Yes, you can do that. And it shows you how they implemented stuff.

                      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