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

Andre Somers andre at familiesomers.nl
Wed Feb 9 14:53:58 CET 2011


Op Wo, 9 februari, 2011 2:28 pm, schreef Niels Dekker \(Qt-interest\):
> Oliver Knoll wrote:
>> Well, what is the motivation of this discussion anyway? ;) Are we
>> talking about a possible future Qt API extension (in the form of some
>> Q_CREATE_UI macro or "setup" method)? Or a design pattern that would
>> be useful for everyone to follow? Or even a design pattern that Qt
>> Creator should apply when auto-generating classes? A question of
>> taste "reference vs pointer"? ;)
>
> My initial motivation was just to share my idea, to see if other Qt users
> like the idea. Also I would like to know if there aren't any
> technicalities
> that I might have overseen. And I must say, the feedback you guys gave me
> so
> far was very useful to me.
>
> 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.

Actually, that is *not* entirely beyond your control. If you really want
this in Qt, you could prepare a patch and request a merge via Gitorious.
It is not an easy route though. There is work underway to make Qt
development even more open (the open governance model), but that is no
reality yet.

To be honest, I have so far not seen a convincing argument on why this
really would be better. I understand that it might be nice to have your UI
as a (const) member of your class, but that will still not make the actual
widgets inside it (const) members. Those are still pointers, and will stay
that way. So, instead of
m_ui->leSomeLineEdit->setText(QString("FooBar"));
you would get
m_ui.leSomeLineEdit->setText(QString("FooBar"));
That doesn't help all that much to get rid of the ->'s you seem to find
dangerous.


André





More information about the Qt-interest-old mailing list