will destroyed() be emitted if the constructor of a class derived from QObject throws?
- by PorkyBrain
Ive seen Qt GUI syntax like the following all over the place:
myDialog::myDialog(QWidget *parent, Qt::WFlags flags):QDialog(parent, flags)
{
QPushButton *button = new QPushButton("&Download", this);
QVBoxLayout *layout = new QVBoxLayout(this);
//something that can throw here
layout ->addWidget(button );
setLayout(layout);
}
I've always wondered if this can leak in the event of an exception because the "this" I'm giving as a parent to button and layout is not fully constructed so it might not destroy its children.
I tried it out in MSVC2010 Qt4.8.3 and it looks like as soon as the base QObject class is fully created (which is done first of course) it is ok to pass "this" to other objects in the constructor, they will destroyed correctly.
I haven't found the spot in the Qt docs guaranteeing this though, can someone point me to it so I have assurance that this will not change in the future?