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

QT4: how to generate header files from ui



  • I'm working on a legacy project written in cpp under Visual Studio 2010. This is a desktop application built with QT4.

    I'm an absolute beginner in the QT world, so maybe the question I'm going to ask is really trivial but I didn't find a simple solution to my problem. As you can see from the screenshoot below (taken from the visual studio project), there are 15 "header" and "cpp" files which have the same name as the "ui" files, so I guess there is a way to automatically generate them. Do you know how to generate them? Because they are missing from the solution.

    Thanks for reading

    2505c721-f71b-40b8-992a-3f671606faf1-immagine.png



  • .ui files are generated with qt designer. ui_ and moc_ files are created whenever ui and widget files are compiled. If you make clean, ui_ and moc_ files will be cleared.
    Try to double click any .ui file, qt designed may pop-up


  • Lifetime Qt Champion

    @brianenno said in QT4: how to generate header files from ui:

    Do you know how to generate them? Because they are missing from the solution.

    These files are auto-generated and should NOT be added directly to the project (and not added to code version systems)! And you also should not edit this generated files manually as you will loose your changes next time these files are generated.
    Take a look at https://doc.qt.io/qt-5/designer-using-a-ui-file.html and https://doc.qt.io/qt-5/moc.html for more information



  • Hi, thanks @JoeCFD and @jsulm for your replies.
    But I'm still struggling with the solution build. I think I have successfully installed QT4 and QTCreator because if I "double click" on the .ui file, the QT Designer is popped up properly and I can see the form.

    But I really didn't understand what is the purpose of the "uic" command. If I try to execute the command, I get a cpp class content.

    @jsulm in visual studio I tried to get rid of those files and tried to re-compile the code from scratch and I get the following error:

    CustomBuild:
      Moc'ing qextserialbase.h...
      The system cannot find the path specified.
      Moc'ing qextserialenumerator.h...
      The system cannot find the path specified.
      Moc'ing qextserialport.h...
      The system cannot find the path specified.
      Moc'ing win_qextserialport.h...
      The system cannot find the path specified.
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(151,5): error MSB6006: "cmd.exe" exited with code 3.
    
    

    That's really strange because (for example) the file "qextserialenumerator.h" is present in the directory.

    What is the purpose of "moc-ing"? Why it is trying to "moc" my qt files?
    Thanks for reading
    Brianenno


  • Lifetime Qt Champion

    Hi

    The UIC converts the UI files to c++ code.
    https://doc.qt.io/qt-5/uic.html
    so it parses the UI file and generates code that will create that layout.

    Moc'ing
    https://doc.qt.io/qt-5/why-moc.html
    https://doc.qt.io/qt-5/moc.html


Log in to reply