Reply
Thread Tools
Posts: 50 | Thanked: 100 times | Joined on Jan 2012 @ Tampere, Finland
#1
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?
 
qwazix's Avatar
Moderator | Posts: 2,622 | Thanked: 5,447 times | Joined on Jan 2010
#2
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.
__________________
Proud coding competition 2012 winner: ρcam
My other apps: speedcrunch N9 N900 Jolla –– contactlaunch –– timenow

Nemo UX blog: Grog
My website: qwazix.com
My job: oob
 
xerxes2's Avatar
Posts: 513 | Thanked: 651 times | Joined on Feb 2011 @ Sweden
#3
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
__________________
But the WM7 "horse" has a blood lineage tracing back to donkeys such as WM6.5, 6.1, 6.0, 5.1 that was fully neglected for too many years and Microsoft did sweet F all to maintain it (still running on Pocket IE4/6!!).
 
pycage's Avatar
Posts: 3,404 | Thanked: 4,474 times | Joined on Oct 2005 @ Germany
#4
How about

Code:
app->setQuitOnLastWindowClosed(false);
in main.cpp?
__________________
Tidings - RSS and Podcast aggregator for Jolla - https://github.com/pycage/tidings
Cargo Dock - file/cloud manager for Jolla - https://github.com/pycage/cargodock
 

The Following User Says Thank You to pycage For This Useful Post:
javispedro's Avatar
Posts: 2,355 | Thanked: 5,249 times | Joined on Jan 2009 @ Barcelona
#5
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
 
Posts: 50 | Thanked: 100 times | Joined on Jan 2012 @ Tampere, Finland
#6
Originally Posted by pycage View Post
Code:
app->setQuitOnLastWindowClosed(false);
Does not work - the main loop still exits. Same with Harmattan.
 
Posts: 50 | Thanked: 100 times | Joined on Jan 2012 @ Tampere, Finland
#7
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.
 
coderus's Avatar
Posts: 6,436 | Thanked: 12,699 times | Joined on Nov 2011 @ Ängelholm, Sweden
#8
why you need this? isnt better to rewrite logics?
set event filter, catch close event, do whatever.
__________________
Telegram | Openrepos | GitHub | Revolut donations
 
xerxes2's Avatar
Posts: 513 | Thanked: 651 times | Joined on Feb 2011 @ Sweden
#9
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
__________________
But the WM7 "horse" has a blood lineage tracing back to donkeys such as WM6.5, 6.1, 6.0, 5.1 that was fully neglected for too many years and Microsoft did sweet F all to maintain it (still running on Pocket IE4/6!!).

Last edited by xerxes2; 2013-12-04 at 20:03.
 
Posts: 50 | Thanked: 100 times | Joined on Jan 2012 @ Tampere, Finland
#10
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.
 
Reply


 
Forum Jump


All times are GMT. The time now is 16:36.