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

Basic Question - Regenerating a new ui_programname.h file



  • Hi,

    So, working through Blanchette & Summerfield.
    After creating a gui interface filled with widgets in the GUI editor, how do you force it to update the code after you make a change to the GUI?
    I tried running qmake again - No joy.

    Also, when you run qmake, it seems to create an entire file structure, which then creates said ui_programname.h.
    In my case, it made it completely outside the file structure of my particular project.
    Are you then expected to manually copy the ui_programname.h to your own file structure and add it manually?
    If not, are there settings in the Qt IDE to make this happen?

    Many thanks.

    Uberlinc.



  • Edit: I found that qmake wasn't updating the file because I had it open elsewhere in Notepad++.
    However, it still re-generated it in the file structure aside from my main project.

    Can this be changed?
    Are you then required to move the file to your own file structure prior to recompiling?
    How does this work?

    Thanks.

    Uberlinc.


  • Qt Champions 2019

    @uberlinc said in Basic Question - Regenerating a new ui_programname.h file:

    which then creates said ui_programname.h.

    The ui_foo.h is not created by qmake but by uic during make. Since there is a dependency, the ui_foo.h is rebuild once the foo.ui file changes. But you can also simply remove the ui_foo.h file to be sure.



  • Thank you for this.

    So, the uic will create ui_foo.h but always in a completely different file structure?
    Are you required to move this file?
    Can you leave it where it is?
    Are there options in the IDE that will configure uic to create these files within your project (for neatness etc.)?

    Thanks.


  • Lifetime Qt Champion

    Hi

    • So, the uic will create ui_foo.h but always in a completely different file structure?-
      Its created in the build folder, just like any other build file.

    Are you required to move this file?
    Nope.
    Can you leave it where it is?
    Indeed. There is no reason to do anything with it.

    Are there options in the IDE that will configure uic to create these files within your project (for neatness etc.)?
    you can tell where UIC should place it with
    UI_DIR = xxxx
    https://doc.qt.io/qt-5/qmake-variable-reference.html

    however, i don't see anything neat about having it in the project folder as they build artifacts and belong in the build folder. :)

    Whenever you change the UI file, its ui_xxx files is generated again so in most cases you can simply
    ignore these files, just like .o files and the other files that are generated.

    The "outside the file structure of my particular project." is called a build folder and "work" files are put there during compile and linking.



  • Thanks, mrjj.
    Those are pretty full and comprehensive answers to my questions.

    One more: If this file is somewhat ignorable, are required to #include them in any particular file?
    If so, then which file path do you specify or do you simply not qualify a path and it knows where to pick it up?

    Thanks again.


  • Lifetime Qt Champion

    Hi
    Normally they are auto inserted into the corresponding cpp file
    #include "ui_mainwindow.h"
    where the .h will use a forward declaration
    namespace Ui {
    class MainWindow;
    }

    This happens automatically if you use the Wizard and select
    alt text

    you get both ui/cpp/and h file with it all setup and nothing more is needed.

    However, if you manually build by hand every file then yes, you would have to
    include it manually.



  • Thank you very much, mrjj,

    You've been wonderfully helpful!


Log in to reply