[Qt-interest] QDialog::closeEvent() is called only when a modal dialog is closed by clicking the "X" button

Constantin Makshin cmakshin at gmail.com
Thu Jun 30 13:10:45 CEST 2011


reject() is a slot, so it doesn't make any sense to call it when the user presses the "X" button. Moreover, if reject() closed the dialog instead of just hiding it, calling this function from closeEvent() might cause an infinite loop (closeEvent() → reject() → close() → closeEvent() → ...).

Also, I've looked at the QDialog source code and found that QDialog::done() finishes the dialog's event loop by calling "d->close_helper(QWidgetPrivate::CloseNoEvent);", i.e. it actually closes the dialog, but does that without calling the closeEvent() function. I guess it works this way to avoid the aforesaid infinite loop, but IMHO it'd be better to add a "the dialog is being closed by the done() slot" boolean flag and let QDialog::closeEvent() choose whether reject() should be called or not based on this flag's value.

On Wednesday, June 29, 2011 03:39:17 PM Zeljko wrote:
> Andre Somers wrote:
> 
> > This behavior is totally logical.
> > If accept and reject would actually destroy the object, it would be
> > impossible to use code to retrieve values from the dialog afterwards. The
> > pointer to the dialog would have become invalid behind your back!
> 
> They should not destroy object, that's normal but close should be called in any 
> case. Why reject() (hide()) isn't called when you click 'X' button ?
> IMO, current behaviour is pretty messy.
> 
> zeljko
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110630/32211d63/attachment.bin 


More information about the Qt-interest-old mailing list