[Qt-interest] QDialog::closeEvent() is called only when a modal dialog is closed by clicking the "X" button
Andre Somers
andre at familiesomers.nl
Tue Jun 28 16:45:01 CEST 2011
Hi,
On Tue, June 28, 2011 4:35 pm, Constantin Makshin wrote:
> Well, after paying a bit more attention to QDialog documentation I've
> found that accept() and reject() slots *hide* the dialog instead of
> closing it. But these slots' "friend" â the done() slot â *closes* the
> dialog (according to the documentation). So the behavior still looks weird
> as IMHO one would expect that accept() and reject() are simply convenience
> wrappers around done() and therefore the dialog should be closed, not just
> hidden...
>
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!
André
> As a workaround, I've used the event() function and put the parameter
> saving code into the "if (event->type() == QEvent::Close ||
> event()->type() == QEvent::Hide)" block. But I'd appreciate more detailed
> information about QDialog's "close vs. hide" question.
>
> On Tuesday, June 28, 2011 06:08:07 PM Zeljko wrote:
>> Constantin Makshin wrote:
>>
>> > Hello!
>> >
>> > I want to save some modal dialog's parameters when it's closed and
>> restore
>> > them when it's created/opened again. The obvious way is to save
>> parameters
>> > inside the closeEvent() function and restore inside the constructor.
>> This
>> > approach works for QMainWindow derivatives but has some weird behavior
>> for
>> > modal dialogs â closeEvent() is called only when the dialog is
>> closed by
>> > clicking the "X" button or choosing corresponding window context menu
>> item. If
>> > the user presses "OK" or "Cancel" button (or takes some other action
>> that's
>> > connected to accept() or reject()), closeEvent() is not called, making
>> the
>> > dialog-parameter-saving idea mostly useless.
>> >
>> > Is this a bug or intended behavior?
>>
>> I guess it's bug, since closeEvent() should be passed before real
>> closing ...and
>> there you can stop it. eg. "Do you really want to close this window (no
>> matter
>> that's modal window or dialog or whatever" ...especially if that
>> triggers on
>> close button ("X").
>>
>> zeljko
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list