PDA

View Full Version : Why a Qwidget extended class does not receive parent ?



tonnot
16th March 2011, 14:34
Is a very basic QT question :
At adressbook example I see :


at h : class NewAddressTab : public QWidget ()
at cpp : NewAddressTab::NewAddressTab(QWidget *parent){...}

Why it is not neccesary to pass parent ?
Thanks

Archa4
16th March 2011, 15:12
If I understand correctly - In this example NewAddressTab is subclassing QWidget, why would it need a parent?
It has no parent, cause it is the main widget
I cannot be sure though, that anything i said is true...

tonnot
16th March 2011, 16:52
In the sense of, for example, another element extending Qtabwidget is written :

AddressWidget::AddressWidget(QWidget *parent) : QTabWidget(parent) {... }
Why then NewAddresTab are not like this :

NewAddressTab::NewAddressTab(QWidget *parent) : QWidget (parent) {...} ????

high_flyer
16th March 2011, 17:08
Because this example is using QWidget's default constructor.
You could pass the parent to QWidget if you wanted to.
Its a matter of design decision based on the needs and uses of the class and software.
I don't know why the trolls decided to declare the constructor with a parent, but not use it.
Maybe originally it was meant to be destroyed by the parent as Qt classes do.
This one however will not.

tonnot
16th March 2011, 17:12
Aha ! I understand.
Thanks