PDA

View Full Version : simple Question about QDialog::closeEvent(...)



momesana
16th February 2008, 16:31
Hi all, one would assume that closeEvent is called whenever the window/dialog is closed. I experimented around with a Dialog whose geometry I wanted to save. I had previously thought that the QDialog::accept() and QDialog::reject() slots indirectly invoke the closeEvent() since the dialog is closed after calling them per default. But closeEvent is only invoked when I hit the title bar close button. But shouldn't closeEvent be called no matter what leads to the closing of the dialog? After all it is _closed_ and one would expect closeEvent to be called!

example: 1992

Thanx in advance

marcel
16th February 2008, 18:09
Because the accept and reject impl look like this(notice the close helper):


void QDialog::done(int r)
{
Q_D(QDialog);
hide();
setResult(r);
d->close_helper(QWidgetPrivate::CloseNoEvent);
emit finished(r);
if (r == Accepted)
emit accepted();
else if (r == Rejected)
emit rejected();
}

/*!
Hides the modal dialog and sets the result code to \c Accepted.

\sa reject() done()
*/

void QDialog::accept()
{
done(Accepted);
}

/*!
Hides the modal dialog and sets the result code to \c Rejected.

\sa accept() done()
*/

void QDialog::reject()
{
done(Rejected);
}
If you would like the closeEvent to get called then don't use their slots.
Or you could use the finished signal instead the close event.

The close_helper is implemented in QWidget.cpp