Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator - ui as private member instead of inheriting from it.

Qt Creator - ui as private member instead of inheriting from it.

Scheduled Pinned Locked Moved Qt Creator and other tools
8 Posts 7 Posters 7.1k 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.
  • F Offline
    F Offline
    fcrochik
    wrote on last edited by
    #1

    I came across the book "C++ GUI Programming with Qt 4" "(1st Edition is available online":http://www.qtrac.eu/C++-GUI-Programming-with-Qt-4-1st-ed.zip) and found very interesting that on their examples the "ui" class is used as base for the widget (window, dialog) and not like Qt creator does as a "private member".

    I have never bothered creating it by hand so have always used the code generated by qt creator. Now after reading the example, I actually like the "multi inheritance" approach better - no more "ui->...." business...

    I am looking at the first edition, does anybody know any good reason for the shift in "recommended" methods?

    Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

    1 Reply Last reply
    0
    • A Offline
      A Offline
      anselmolsm
      wrote on last edited by
      #2

      Good question. As I rarely develop stuff using ui / qt designer (most of my projects uses QGW or QML), when I need to use it I always ask myself what's the best approach. I like the inheritance way, but is not based on any good reason.

      Anselmo L. S. Melo (anselmolsm)

      1 Reply Last reply
      0
      • ZlatomirZ Offline
        ZlatomirZ Offline
        Zlatomir
        wrote on last edited by
        #3

        I like the private member approach, because the code is better encapsulated this way and the generated code is separated from my own (written by me) code.

        And as a disadvantage i can mention the fact that you might need to code more signals and slots just to keep the ui pointer (or member) private.

        https://forum.qt.io/category/41/romanian

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          Hi,

          If I use the desugner, I always use the private aproach to encapsulate the members as members, not base class. But normally, I code the UI by hand :-) if I do UI stuff.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • B Offline
            B Offline
            baysmith
            wrote on last edited by
            #5

            The decision should be made based on how the class will be used. A private ui pointer has the advantage of keeping the UI private. Doing so restricts the interface of the class, which is a good thing because it cuts down on potential coupling between classes. However, if the class needs to be used as the widget defined by the UI, then inheritance is necessary.

            Nokia Certified Qt Specialist.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              In the "Qt Tips and Tricks" track on DevDays 2010 they recommended to use the private pointer method. Unfortunately I cannot remember the reason why, so we'll have to wait for the videos :-)

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • D Offline
                D Offline
                disperso
                wrote on last edited by
                #7

                [quote author="Volker" date="1292189521"]In the "Qt Tips and Tricks" track on DevDays 2010 they recommended to use the private pointer method. Unfortunately I cannot remember the reason why, so we'll have to wait for the videos :-)[/quote]

                Because of binary compatibility. It's used extensively on Qt and on KDE libs. It's called "d-pointer" very frequently:

                "http://en.wikipedia.org/wiki/Opaque_pointer":http://en.wikipedia.org/wiki/Opaque_pointer
                "http://techbase.kde.org/Policies/Library_Code_Policy#D-Pointers":http://techbase.kde.org/Policies/Library_Code_Policy#D-Pointers

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  With regard to BC that's the only choice, true. But that's mainly an issue with libs. In applications it's not that important, IMHO. But you're right - in general it's the easiest approach and does not cause any troubles. Multiple inheritance can be confusing too :-)

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  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