[Qt-interest] Quit vs. Close window

Israel Brewster israel at frontierflying.com
Tue Dec 30 18:22:22 CET 2008


Hmmm.... close, but no cigar. The problem here being my particular use  
of this differentiation. In my application when the close event is  
first emitted, and thus the closeEvent function called, the window  
being closed IS the last window. The close event then opens a  
different window and sets a few flags before closing- specifically the  
window that is closing is a document view window, and when it is  
closed I have a document selection window open, and set a couple of  
flags in the settings file specifying the last state. However, when I  
quit, I don't want the other window to open, or the flags to be set.  
This code wouldn't work, because at the point I need to check the  
window being closed is the last window. Tony Rietwyk suggested setting  
a flag in the file/exit routine, which should work, so unless there is  
a more automatic way of telling the difference, I'll probably just go  
with that. Thanks again.
-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------


On Dec 29, 2008, at 6:30 PM, Bill KING wrote:

> This chunk of code from QWidgetPrivate::close_helper() may help a bit,
> it's the determinant code for weither lastWindowClosed() signal is
> emitted, and may be reworked inside your code to determine whether  
> to do
> close or quit behaviour.
>
>    // Attempt to close the application only if this widget has the
>    // WA_QuitOnClose flag set set and has a non-visible parent
>    quitOnClose = quitOnClose && (parentWidget.isNull() ||
> !parentWidget->isVisible() ||
> parentWidget->testAttribute(Qt::WA_DontShowOnScreen));
>
>    if (quitOnClose) {
>        // If there is no non-withdrawn primary window left (except
>        // the ones without QuitOnClose or with WA_DontShowOnScreen),
>        // we emit the lastWindowClosed signal
>        QWidgetList list = QApplication::topLevelWidgets();
>        bool lastWindowClosed = true;
>        for (int i = 0; i < list.size(); ++i) {
>            QWidget *w = list.at(i);
>            if ((w->isVisible() &&
> !w->testAttribute(Qt::WA_DontShowOnScreen))
>                    && !w->parentWidget() &&
> w->testAttribute(Qt::WA_QuitOnClose)) {
>                lastWindowClosed = false;
>                break;
>            }
>        }
>        if (lastWindowClosed)
>            QApplicationPrivate::emitLastWindowClosed();
>    }
>
>
>
> Israel Brewster wrote:
>> How can I handle a close window command (such as when the user clicks
>> the close button) differently than a quit (or exit, if you prefer)
>> command? I have made a custom implementation of the closeEvent()
>> function to do some stuff when the user closes the window, and this
>> works. However, this is also called when you choose to quit the
>> application, which I don't want to happen- I only want the function  
>> to
>> run when the user manually closes the window. How can I implement
>> this? is there some sort of flag I can look for that lets me know the
>> application is closing? Or a specific signal that is emitted when the
>> close button is pressed that is not emitted when the application
>> exits? Thanks.
>>
>> -----------------------------------------------
>> Israel Brewster
>> Computer Support Technician
>> Frontier Flying Service Inc.
>> 5245 Airport Industrial Rd
>> Fairbanks, AK 99709
>> (907) 450-7250 x293
>> -----------------------------------------------
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>
>
> -- 
> Bill King, Software Engineer
> Qt Software, Nokia Pty Ltd
> Brisbane Office




More information about the Qt-interest-old mailing list