[Qt-interest] A new (?) const-correct way to create a Ui object and do setupUi
Thiago Macieira
thiago at kde.org
Tue Feb 8 12:04:16 CET 2011
Em terça-feira, 8 de fevereiro de 2011, às 11:50:03, Robert Hairgrove
escreveu:
> If "ui" is const, you cannot call any of the non-const functions on any
> of the GUI objects it contains ... such as setText() on an edit control,
> for example. I think this would be severely limiting.
Hello Robert
That is not correct. If the "ui" object is const, its members are const. That
means if you a QTextEdit* as a member, the *pointer* becomes const, not the
pointed object.
So you can do this:
ui->textEdit->setText("foo");
But you can't do this:
ui->textEdit = new QTextEdit(this);
> As to deletion, normally the parent of an object which inherits QObject
> will delete its children automatically. I would think that creating ui
> as a member object variable would lead to a double deletion, but I might
> be mistaken.
No, there's no double deletion. The Ui_* classes have no constructor or
destructors. So they don't delete the form elements that setupUi creates. They
contain only pointers, so these classes are effectively POD.
However, the Ui class itself must be deleted if it was newed.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110208/020ef15c/attachment.bin
More information about the Qt-interest-old
mailing list