[Qt-interest] A new (?) const-correct way to create aUiobjectand do setupUi

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Feb 9 14:56:15 CET 2011


On 2011-02-09 Niels Niels Dekker (Qt-interest) wrote:

> I would certainly like it very much if a function like createAndSetupUi would
> become part of Qt. But that's beyond my control, of course  :-) I don't think it
> needs to be a macro. It's just a template function.

Let's put it this way: if there was a Qt API which would provide such a solution and which would let me assign the generated "UI instance" to either a const refererence or just a reference at my option I would use it.

But for all practical manners the "traditional" approach by simply allocating the "UI instance" to a pointer and deleting it in the d'tor is simple enough for me, and almost a "Qt institutionalised thing", so I would not botter to write this extra code for myself. I agree with all your motivating points and personally I also try to make "everything const where possible" and prefer references over pointers, exactly for the reasons you have mentioned ("now could this pointer be 0 here or not?"). But when it comes to the 'ui' member I think I am "conditioned" enough to not worry about its usage ;)

As to the const'ness of the ui instance: I can't think of any practical scenario right now where one would like to "fix" the initial UI design forever, that is not needing to deleting certain widgets at runtime (and hence modifying the pointers inside the UI instance) - but having at least the option to assign it to a non-const reference would be desirable. Besides the already mentioned problematic with "retranslateUi" (which could be solved by changing the argument to be const).

Thanks for sharing your ideas!
  Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22





More information about the Qt-interest-old mailing list