I have to do it this way, because after dial.exec() i'm doing some more stuff, depends on if dialog was accepted or rejected.
from what I understood, does not close the exact same moment the showDialog() method finished, hence it did not get deleted (or it would either close the dialog or crash)
Actually i did some experimets. I wrote my own QLabel, i mean class which inherits from QLabel and which shows up message box when destructor is called.
{
Q_OBJECT
public:
~myLabel
() { QMessageBox::information(this,
"asd",
"label destructor");
};
};
class myLabel : public QLabel
{
Q_OBJECT
public:
myLabel(const QString & text, QWidget * parent = 0) : QLabel(text,parent) {};
~myLabel() { QMessageBox::information(this, "asd", "label destructor"); };
};
To copy to clipboard, switch view to plain text mode
And in dialog.cpp
{
label = new myLabel("Seomthing", this);
lay->addWidget(label);
lay->addWidget(edit);
lay->addWidget(button);
setLayout(lay);
}
dialog::~dialog()
{
QMessageBox::information(this,
"asd",
"Dialog destructor");
}
dialog::dialog(QWidget *parent)
: QDialog(parent)
{
label = new myLabel("Seomthing", this);
edit = new QLineEdit(this);
button = new QPushButton("My Button", this);
lay = new QVBoxLayout;
lay->addWidget(label);
lay->addWidget(edit);
lay->addWidget(button);
setLayout(lay);
}
dialog::~dialog()
{
QMessageBox::information(this, "asd", "Dialog destructor");
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
void test::showDialog()
{
dialog dial;
dial.setGeometry(100,100,200,200);
dial.exec();
}
void test::showDialog()
{
dialog dial;
dial.setGeometry(100,100,200,200);
dial.exec();
QMessageBox::information(this, "asd", "Function");
}
To copy to clipboard, switch view to plain text mode
And what i'm getting in result of this program (after showing dialog) is:
Function
Dialog destructor
label destructor
So it means that destructors are called fine, but still in this simple example. Memory usage before dialog: 2160K, during dialog is opened: 2668K, after dialog closed: 2408K (i did measurs without messageboxes)
EDIT
If i add this flag, program is crashing after window closes.
Bookmarks