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. QT4: how to generate header files from ui
Forum Update on Monday, May 27th 2025

QT4: how to generate header files from ui

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 3.0k Views
  • 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.
  • B Offline
    B Offline
    brianenno
    wrote on 10 Jun 2021, 14:28 last edited by
    #1

    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

    J 1 Reply Last reply 11 Jun 2021, 06:52
    0
    • J Offline
      J Offline
      JoeCFD
      wrote on 10 Jun 2021, 14:56 last edited by JoeCFD 6 Oct 2021, 14:59
      #2

      .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

      1 Reply Last reply
      0
      • B brianenno
        10 Jun 2021, 14:28

        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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 11 Jun 2021, 06:52 last edited by jsulm 6 Nov 2021, 06:54
        #3

        @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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • B Offline
          B Offline
          brianenno
          wrote on 12 Jun 2021, 17:07 last edited by
          #4

          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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 12 Jun 2021, 19:51 last edited by mrjj 6 Dec 2021, 19:51
            #5

            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

            1 Reply Last reply
            1

            4/5

            12 Jun 2021, 17:07

            • Login

            • Login or register to search.
            4 out of 5
            • First post
              4/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved