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. What are the purposes of .ui and ui...h files?

What are the purposes of .ui and ui...h files?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 2.8k 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.
  • nulluseN Offline
    nulluseN Offline
    nulluse
    wrote on last edited by
    #1

    Can anyone explain why there are both ui...h and .ui files for a form widget?
    I just cannot grasp the idea of having an XML file that defined the structure of a form and its UI elements, plus a .h file with the same.

    In JavaFX there is just XML to inject into an application, or you can define everything in the code. This is kind of intuitive, but both code and XML, which also can be out of sync (as I have demonstrated in the thread about disabling the shadow build to recover from QtCreator not updating the .h after X number of UI elements added to the form) sounds kind of redundant.

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You can use the .ui files similarly to Java. There's a QUiLoader class for that. XML is also a good format to store ui for a visual editor (Qt Designer in this case).
      But this is C++. Performance matters. Loading an XML at runtime and parsing it may be fine for smaller UIs but in general that's sub-optimal and usually plain unacceptable.
      The uic tool parses the xml and generates a c++ header file. This file is then compiled like any other of your cpp/h files into native code and there's no additional I/O or parsing needed at runtime. The compiled ui is not a resource/data but an executable code.

      1 Reply Last reply
      3
      • nulluseN Offline
        nulluseN Offline
        nulluse
        wrote on last edited by
        #3

        That does not really answer my question as it does not address the reason for having both.

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That does not really answer my question

          I thought it did. The reason is that XML is a better format for editors - generation, validation, merging etc. and c++ code generation and compilation is used to get better performance at runtime.

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            Treat the .h file as you treat moc_ files: you don't need them as you can generate them from the .ui files but if the source did not change you don't need to reparse and rebuild them.

            Basically, feel free to delete the generated headers

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            0
            • nulluseN Offline
              nulluseN Offline
              nulluse
              wrote on last edited by
              #6

              How can I force generation of the .h file in QtCreator?

              1 Reply Last reply
              0
              • Chris KawaC Online
                Chris KawaC Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by Chris Kawa
                #7

                If the .ui file is part of the project then qmake will detect changes to the file and run uic when you build. Running uic directly is not exposed in the IDE because there's no need to do that. That's the thing - the syncing you complained about does not require any interaction from you. It's done by the build system. Generated ui_...h files are implementation detail.

                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