The question is as in the title.
For example:
QPropertyAnimation *animation;
animation = new QPropertyAnimation(this, "windowOpacity", this);
or
QPropertyAnimation animation;
animation.setTargetObject(this);
animation.setPropertyName("windowOpacity");
animation.setParent(this);
Which is more efficient?
edit: though it has no significant difference unless done repeatedly, i would still like to know, i would rather want answers than opinions -as stackoverflow’s guidelines suggest.
First, why
newin the first example? I’ll assume that you will create both variables on the same storage (heap / stack).Second, this isn’t a matter of Qt, it applies to C++ in general.
Without any prior knowledge about the class you are creating, you can be sure of one thing: The constructor with arguments version is at least as efficient as the setter version.
This is because, in the worst case, the constructor might look like this:
However, any person that has atleast worked through a good book will write the constructor like this: