Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QT4: how to generate header files from ui

    General and Desktop
    4
    5
    573
    Loading More Posts
    • 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
      brianenno last edited by

      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

      jsulm 1 Reply Last reply Reply Quote 0
      • JoeCFD
        JoeCFD last edited by JoeCFD

        .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 Reply Quote 0
        • jsulm
          jsulm Lifetime Qt Champion @brianenno last edited by jsulm

          @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 Reply Quote 3
          • B
            brianenno last edited by

            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 Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion last edited by mrjj

              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 Reply Quote 1
              • First post
                Last post