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. QObject* parent instead of QObject *parent
Forum Updated to NodeBB v4.3 + New Features

QObject* parent instead of QObject *parent

Scheduled Pinned Locked Moved Qt Creator and other tools
12 Posts 6 Posters 7.9k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    tobias.hunger
    wrote on last edited by
    #2

    I am not aware of such an option.

    Feel free to file a feature request in our "bugtracker":http://bugreports.qt.nokia.com/

    Of course you can also fix the issue yourself and file a "merge request":http://qt.gitorious.org/qt-creator with the changes.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      markus.liebe
      wrote on last edited by
      #3

      I read in the "QtCodingStyle":http://qt.gitorious.org/qt/pages/QtCodingStyle document (section whitespace) that the preferred style is not QObject* parent but QObject *parent.

      @the Trolls: what are the advantages of the chosen style? What are the reasons that made you choose it?

      I know it is quite subjective, but I prefer the first style (QObject* parent instead of QObject *parent).

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #4

        Markus: I do not know, that coding style was in effect long before I joined the company:-)

        The reasoning I saw somewhere else was that the latter style makes it more clear that the name "parent" is a pointer since the * goes with the name of the variable.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Panke
          wrote on last edited by
          #5

          I prefer the "T* name" Style because the type of name is pointer to T, so the * belongs to the type, not
          to the name. One argument for the "T *name" style is, that it is consistent to multiple variable declarations on the same line, but this is something I don't do anyway.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DrMaboule
            wrote on last edited by
            #6

            I fact you could declare more than one variable using this code:

            QObject *pParent = NULL, *pParent2 = NULL; // Two pointer

            But is différent from

            QObject *pParent = NULL, pParent; // One pointer and a none pointer object.

            So I think QObject pParent is better than QObjet pParent;

            QObject pParent : The variable is a pointer on a objet of type QObject. QObject is not a class but a pointer on a class. The variable is a pointer, so * should be next the variable.

            Don't you agreed?

            note : I use QObject* pParent"since 6 years but try to change this.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #7

              DrMaboule: QObject based objects should not get allocated on the stack, since mixing memory management based on the C++ stack with Qt's parent-child relation can get really messy:-)

              I consider the information "pointer of type A" is better transported by writing A*. I hardly ever see "A a, b" in code, so I really do not consider whether that is a bit more readable or not at all important.

              In the end the most important thing is to be consistent with the surrounding code, so I end up using whichever style is already there. In code not effected by existing coding standards I go for "A*".

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sabrog
                wrote on last edited by
                #8

                For C language

                @MyStruct *myStruct@

                , for C++

                @MyClass* myClass@.

                This recomendation from "Bjarne Straustrup":http://www2.research.att.com/~bs/bs_faq2.html#whitespace

                QT - Apple QuickTime
                Qt - Nokia's Qt Development Frameworks
                Apple is a competitor of Nokia, so QT != Qt

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DrMaboule
                  wrote on last edited by
                  #9

                  Thanks for this answer and this link.

                  See you in another topic.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tobias.hunger
                    wrote on last edited by
                    #10

                    SABROG: Oh, you broke the thread:-)

                    Who dares to contradict Stroustrup?

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lyuts
                      wrote on last edited by
                      #11

                      Panke, see the Qt Creator plugin gallery "here":http://developer.qt.nokia.com/wiki/Qt_Creator_Plug-in_Gallery . There is AStlyle plugin. But there is a limitation, it is only for Qt Creator 1.3.1. We'll hope it gets updated.

                      I'm a rebel in the S.D.G.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Panke
                        wrote on last edited by
                        #12

                        [quote author="DrMaboule" date="1279318875"]I fact you could declare more than one variable using this code:

                        QObject *pParent = NULL, *pParent2 = NULL; // Two pointer

                        But is différent from

                        QObject *pParent = NULL, pParent; // One pointer and a none pointer object.

                        This is something I don't do anyway. I would call this a code smell on its own.
                        [/quote]
                        [quote]
                        QObject pParent : The variable is a pointer on a objet of type QObject. QObject is not a class but a pointer on a class. The variable is a pointer, so * should be next the variable.
                        [/quote]

                        You are right, QObject* is not a class, but a pointer to a class. But it is atype.

                        [quote]
                        Don't you agreed?
                        [/quote]
                        Obviously no, but it is a matter of taste. I'll agree to Tobias Hunger that you should be consistent
                        to the code at hand and for my code it's T* name

                        lyuts thank you for the info.

                        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