Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Closing an application without killing main loop

    Reply
    Page 1 of 3 | 1   2     3   | Next
    vranki | # 1 | 2013-12-04, 17:11 | Report

    Hi,

    I'm writing an application which has to do dome network operations after user has closed the UI. Normally this is not possible, as the applications Qt main loop exits when closing the UI.

    On Harmattan i found a workaround - re-starting the mainloop by calling QGuiApplication::exec(). This seems to crash on Sailfish.

    The next workaround i tried to use is to create an event filter for the QGuiApplication and try to filter out the close event. QEvent::Close never happens, but QEvent::ApplicationDeactivate does. It can be used to prevent killing main loop, but unfortunately it also happens when user swipes the application to the background.

    Any ideas on how can i accomplish this?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    qwazix | # 2 | 2013-12-04, 17:15 | Report

    It's not exactly what you're asking, but you could create a daemon and control it from your application via dbus, so you don't have to work around the close event.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    xerxes2 | # 3 | 2013-12-04, 17:22 | Report

    I think what you want is the aboutToQuit signal which doesn't quit the mainloop until its callback returns.

    http://qt-project.org/doc/qt-5.0/qtc...ml#aboutToQuit

    Edit | Forward | Quote | Quick Reply | Thanks

     
    pycage | # 4 | 2013-12-04, 17:48 | Report

    How about

    Code:
    app->setQuitOnLastWindowClosed(false);
    in main.cpp?

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to pycage For This Useful Post:
    uvatbc

     
    javispedro | # 5 | 2013-12-04, 17:48 | Report

    Originally Posted by vranki View Post
    I'm writing an application which has to do dome network operations after user has closed the UI. Normally this is not possible, as the applications Qt main loop exits when closing the UI.
    Actually the reason is that closing the last window generates a quit event. See http://qt-project.org/doc/qt-4.8/qap...dowClosed-prop

    Edit | Forward | Quote | Quick Reply | Thanks

     
    vranki | # 6 | 2013-12-04, 19:36 | Report

    Originally Posted by pycage View Post
    Code:
    app->setQuitOnLastWindowClosed(false);
    Does not work - the main loop still exits. Same with Harmattan.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    vranki | # 7 | 2013-12-04, 19:47 | Report

    Originally Posted by xerxes2 View Post
    I think what you want is the aboutToQuit signal which doesn't quit the mainloop until its callback returns.

    http://qt-project.org/doc/qt-5.0/qtc...ml#aboutToQuit
    I created a aboutToQuit slot like this:

    Code:
    // Called when app about to quit - handle upsync & quitting
    void ClientLogic::aboutToQuit() {
        qDebug() << Q_FUNC_INFO;
        QEventLoop eventLoop;
        eventLoop.exec();
    }
    On emulator quitting with this results in output:

    Code:
    virtual void ClientLogic::aboutToQuit() 
    The Wayland connection broke. Did the Wayland compositor die?
    Killing all inferiors
    Debugging has finished
    Debugger just displays ??'s as stack trace so it's useless. The crash happens when eventLoop.exec() is called.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    coderus | # 8 | 2013-12-04, 19:54 | Report

    why you need this? isnt better to rewrite logics?
    set event filter, catch close event, do whatever.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    xerxes2 | # 9 | 2013-12-04, 20:00 | Report

    Originally Posted by vranki View Post
    I created a aboutToQuit slot like this:

    Code:
    // Called when app about to quit - handle upsync & quitting
    void ClientLogic::aboutToQuit() {
        qDebug() << Q_FUNC_INFO;
        QEventLoop eventLoop;
        eventLoop.exec();
    }
    On emulator quitting with this results in output:

    Code:
    virtual void ClientLogic::aboutToQuit() 
    The Wayland connection broke. Did the Wayland compositor die?
    Killing all inferiors
    Debugging has finished
    Debugger just displays ??'s as stack trace so it's useless. The crash happens when eventLoop.exec() is called.
    Why are you calling eventLoop.exec()? You already has one mainloop running so just put your cleanup code in the aboutToQuit callback instead. The mainloop will not exit before the aboutToQuit callback returns. There was a bug in earlier sdk but in the latest version it works just fine.

    http://talk.maemo.org/showthread.php...ht=abouttoquit

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by xerxes2; 2013-12-04 at 20:03.

     
    vranki | # 10 | 2013-12-04, 20:05 | Report

    Originally Posted by coderus View Post
    why you need this?
    Because the application needs to synchronize it's state to a remote server when it is closed.

    Originally Posted by coderus View Post
    isnt better to rewrite logics?
    set event filter, catch close event, do whatever.
    I have been planning to make a separate daemon and ui, but due to limited time available i am not going to do this anytime soon.

    I'd be even happy to write a patch to Qt or Sailfish itself if it is the only way and would be accepted into upstream.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Page 1 of 3 | 1   2     3   | Next
vBulletin® Version 3.8.8
Normal Logout