QObject* parent instead of QObject *parent
How can I configure Qt Creator to use the first style instead of the second his auto-generated code? Where can I find the corresponding templates?
11 replies
I am not aware of such an option.
Feel free to file a feature request in our bugtracker [bugreports.qt.nokia.com]
Of course you can also fix the issue yourself and file a merge request [qt.gitorious.org] with the changes.
I read in the QtCodingStyle [qt.gitorious.org] 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).
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.
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*”.
For C language
- MyStruct *myStruct
, for C++
@MyClass* myClass@.
This recomendation from Bjarne Straustrup [.research.att.com]
Panke, see the Qt Creator plugin gallery here [developer.qt.nokia.com] . 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 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.
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.
You are right, QObject* is not a class, but a pointer to a class. But it is a*type*.
Don't you agreed?
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.
You must log in to post a reply. Not a member yet? Register here!



