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. How to create .CPP class for a Form?

How to create .CPP class for a Form?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 2.5k 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.
  • S Offline
    S Offline
    Sprezzatura
    wrote on 15 Sept 2018, 21:05 last edited by
    #1

    I have created a Form "Test" (TEST.UI file) using Qt Creator Form Designer.

    How do I automatically generate the corresponding TEST.CPP file that contains the object definition, creator/destructor, etc?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 Sept 2018, 21:08 last edited by SGaist
      #2

      Hi and welcome to devnet,

      Add UIC += test.ui to your .pro file.

      Add FORMS += test.ui to your .pro file.

      Did you only create the .ui file or did you ask for a widget to be used with designer ? If the later, you should already have everything needed in your .pro file.

      [edit: fixed qmake variable name SGaist]

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 15 Sept 2018, 21:10
      2
      • S SGaist
        15 Sept 2018, 21:08

        Hi and welcome to devnet,

        Add UIC += test.ui to your .pro file.

        Add FORMS += test.ui to your .pro file.

        Did you only create the .ui file or did you ask for a widget to be used with designer ? If the later, you should already have everything needed in your .pro file.

        [edit: fixed qmake variable name SGaist]

        A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 15 Sept 2018, 21:10 last edited by
        #3

        @SGaist shouldn't that be FORMS += test.ui?

        Qt has to stay free or it will die.

        1 Reply Last reply
        1
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 15 Sept 2018, 21:12 last edited by
          #4

          @aha_1980 Yes, you're correct ! Looking at cmake stuff and got it mixed :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 15 Sept 2018, 21:19 last edited by
            #5

            Hi
            I wonder if u choose the wrong template to begin with ?
            alt text

            That one create both .h and .cpp and UI file.

            The one next in list, creates ONLY the UI file.

            1 Reply Last reply
            1
            • S Offline
              S Offline
              Sprezzatura
              wrote on 15 Sept 2018, 22:10 last edited by
              #6

              @SGaist My .PRO file does contain FORMS += test.ui

              @mrjj Yes I do believe I chose "Qt Designer Form" (instead of "Qt Designer Form Class")

              I will try the "Class" version.

              Thank you.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sprezzatura
                wrote on 15 Sept 2018, 22:21 last edited by
                #7

                Yes, that was the problem. The solution is to choose "Qt Designer Form Class".

                I will be writing a utility to convert 300 Win32 Resource dialogs to Qt. I looked at KNUT: by the time I figure out how to compile and run it, I can write the conversion program. Plus, KNUT uses the .EXE, I have an .RC file.

                M 1 Reply Last reply 16 Sept 2018, 01:59
                0
                • S Sprezzatura
                  15 Sept 2018, 22:21

                  Yes, that was the problem. The solution is to choose "Qt Designer Form Class".

                  I will be writing a utility to convert 300 Win32 Resource dialogs to Qt. I looked at KNUT: by the time I figure out how to compile and run it, I can write the conversion program. Plus, KNUT uses the .EXE, I have an .RC file.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 16 Sept 2018, 01:59 last edited by mrjj
                  #8

                  @Sprezzatura
                  Holy mother of old code. 30 300 dialogs in one program?
                  What is knut ? Do you have a link to it ?

                  Note that Qts UI files are XML and could be produced from
                  external application.

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    Sprezzatura
                    wrote on 16 Sept 2018, 13:00 last edited by Sprezzatura
                    #9

                    That's three hundred dialogs, not thirty (includes multi-page Property Sheets) :o)

                    KNUT used to be offered by KDAB, the Qt consulting company. It is no longer mentioned on their site.

                    You can get the source code for KNUT from here:

                    https://www.opendesktop.org/c/1466642231

                    I can see how Qt .UI files are structured. It will be fairly straightforward to convert a Visual Studio .RC to XML. I can even automatically generate the class .CPP and .H files.

                    M 1 Reply Last reply 16 Sept 2018, 15:52
                    1
                    • S Sprezzatura
                      16 Sept 2018, 13:00

                      That's three hundred dialogs, not thirty (includes multi-page Property Sheets) :o)

                      KNUT used to be offered by KDAB, the Qt consulting company. It is no longer mentioned on their site.

                      You can get the source code for KNUT from here:

                      https://www.opendesktop.org/c/1466642231

                      I can see how Qt .UI files are structured. It will be fairly straightforward to convert a Visual Studio .RC to XML. I can even automatically generate the class .CPP and .H files.

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 16 Sept 2018, 15:52 last edited by
                      #10

                      @Sprezzatura
                      Yes, typo :) Thats massive.
                      Ah, that is old :) Qt3 code will need changes to compile
                      on 5.11. But interesting never the less.

                      Just as a note in case you missed it
                      http://doc.qt.io/qt-5/uic.html
                      Qt dont actually use the UI at runtime. its already converted to c++ code.

                      1 Reply Last reply
                      1
                      • S Offline
                        S Offline
                        Sprezzatura
                        wrote on 17 Sept 2018, 12:18 last edited by
                        #11

                        @mrjj and @SGaist Thanks very much for your help. My "RCtoUI" conversion program is starting to produce results. It's great to open up a .UI file with Qt Creator and magically see the dialog appear. It looks like I have to multiply the VS RC dialog units by 2 to get them to scale and look OK in Qt.

                        I will provide a link to download the RCtoUI executable (when it's completed) if anyone is interested.

                        M 1 Reply Last reply 17 Sept 2018, 12:47
                        3
                        • S Sprezzatura
                          17 Sept 2018, 12:18

                          @mrjj and @SGaist Thanks very much for your help. My "RCtoUI" conversion program is starting to produce results. It's great to open up a .UI file with Qt Creator and magically see the dialog appear. It looks like I have to multiply the VS RC dialog units by 2 to get them to scale and look OK in Qt.

                          I will provide a link to download the RCtoUI executable (when it's completed) if anyone is interested.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 17 Sept 2018, 12:47 last edited by
                          #12

                          @Sprezzatura
                          Im pretty sure anyone faced with the task of converting old win32
                          dialog code to Qt would find RCtoUI very useful so please do
                          And congrats with the progress :)

                          1 Reply Last reply
                          0

                          1/12

                          15 Sept 2018, 21:05

                          • Login

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