[Interest] [Android] QMainWindow::closeEvent not raised when user terminates with swipe?

Eddie Sutton edsutton at gmail.com
Tue Apr 7 18:18:26 CEST 2015


[Solved] Thank you Robert!

I hope it works on iOS as well as I expect it will have similar problems.

int main(int argc, char *argv[])
{
    QApplication application(argc, argv);
    cms::MainWindow mainWindow;

    QObject::connect(&application, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
                     &mainWindow, SLOT(applicationStateChanged(Qt::ApplicationState)));






/// Use signal QGuiApplication::applicationStateChanged(Qt::ApplicationState state)
/// to catch Android and hopefull iOS users pressing the home or multi-task button.
/// Under Android, users can press rectangular multi-task button,
/// this will change state to Qt:ApplicationInactive.
///
/// When exiting Qt::ApplicationActive state, save settings.
///
/// Is there any reason to disable this for desktop platforms?
void MainWindow::applicationStateChanged(Qt::ApplicationState state)
{
    static Qt::ApplicationState oldState = Qt::ApplicationSuspended;
    if(oldState == state)
    {
        return;
    }
    oldState = state;
    if(Qt::ApplicationActive == state )
    {
        return;
    }

    Settings::write(Settings::settings(), this);
}


-Ed


> On Apr 7, 2015, at 10:27 AM, Robert Iakobashvili <coroberti at gmail.com> wrote:
> 
> On Tue, Apr 7, 2015 at 6:05 PM, Eddie Sutton <edsutton at gmail.com> wrote:
>> Currently I save QSettings in closeEvent.
>> 
>> On Android this event is not raised when user presses that Android square icon, then swipes app window to close.
>> 
>> How do I handle saving work user may have been editing?
>> 
>> -Ed
> 
> Hi Ed,
> Look at QGuiApplication::applicationStateChanged signal.
> When your app transits from
> Qt::ApplicationActive to anything else (Qt::ApplicationSuspended or
> Qt::ApplicationInactive),
> it's worth to save everything; next user can swipe it out.
> 
> It looks to be a rather cross-platform way,
> and it may work for iOS as well.
> 
> Take care!
> 
> Regards,
> Robert

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150407/091e961e/attachment.html>


More information about the Interest mailing list