Closing an application without killing main loop
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? |
Re: Closing an application without killing main loop
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.
|
Re: Closing an application without killing main loop
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 |
Re: Closing an application without killing main loop
How about
Code:
app->setQuitOnLastWindowClosed(false); |
Re: Closing an application without killing main loop
Quote:
|
Re: Closing an application without killing main loop
Quote:
|
Re: Closing an application without killing main loop
Quote:
Code:
// Called when app about to quit - handle upsync & quittingCode:
virtual void ClientLogic::aboutToQuit() |
Re: Closing an application without killing main loop
why you need this? isnt better to rewrite logics?
set event filter, catch close event, do whatever. |
Re: Closing an application without killing main loop
Quote:
http://talk.maemo.org/showthread.php...ht=abouttoquit |
Re: Closing an application without killing main loop
Quote:
Quote:
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. |
Re: Closing an application without killing main loop
install event filter
|
Re: Closing an application without killing main loop
Quote:
|
Re: Closing an application without killing main loop
Quote:
|
Re: Closing an application without killing main loop
Quote:
|
Re: Closing an application without killing main loop
I think the reason for newly started main loop is in qwaylandeventthread.cpp line 37:
https://qt.gitorious.org/qt/qtwaylan...thread.cpp#L37 When app window is closed, the Wayland connection is broken and if something (in the new mainloop?) calls readWaylandEvents(), the process is killed. |
Re: Closing an application without killing main loop
okay, event filtering seems not to work in emulator, try:
Code:
app->connect( app, SIGNAL(lastWindowClosed()), app, SLOT(quit()) );and Code:
int retVal = app->exec(); |
Re: Closing an application without killing main loop
Quote:
|
Re: Closing an application without killing main loop
what about other methods?
|
Re: Closing an application without killing main loop
Quote:
https://code.google.com/p/qgvdial/so...k/src/main.cpp |
Re: Closing an application without killing main loop
Quote:
|
Re: Closing an application without killing main loop
1 Attachment(s)
I attached a simple test application to this message. It creates a sailfish app and a timer printing a message every second. Before starting the app, it calls app->setQuitOnLastWindowClosed(false).
When you close the window, the mainloop exits and messages stop appearing. Can anyone modify it so that after closing the window it still keeps running? Is current behavior a bug? |
Re: Closing an application without killing main loop
This was a bug in the early SDK releases. Make sure you have the latest SDK.
See also: http://talk.maemo.org/showthread.php?t=91595 Note that I have no problems running this on device. |
Re: Closing an application without killing main loop
Quote:
Quote:
|
Re: Closing an application without killing main loop
Quote:
Quote:
|
Re: Closing an application without killing main loop
Quote:
Alternatively, I suggest resintalling the SDK :-D |
Re: Closing an application without killing main loop
Quote:
Can anyone give a third opinion how the app behaves on close? |
Re: Closing an application without killing main loop
I just tested in SDK with another PC and the application still behaves incorrectly:
Code:
Timer (and main loop) is still alive |
Re: Closing an application without killing main loop
The issue is now resolved. The bug was in still in latest SDK and was recently fixed by a SDK update. It also works correctly on device. Thanks for help!
|
Re: Closing an application without killing main loop
No I am really confused.
Because in my case my app dont leave mainloop and in my case I want it to leave :confused: Code:
|
Re: Closing an application without killing main loop
maybe just emulator bug. test on device and ignore emulator bug if arm build works okay :)
|
| All times are GMT. The time now is 13:25. |
vBulletin® Version 3.8.8