[Interest] Triggering Actions on Application Close
franki
franki at franki.eu.org
Wed Jul 10 14:23:25 CEST 2013
Dnia wtorek, 9 lipca 2013 o 00:33:44 Mitchell Verter napisaĆ(a):
> How do I trigger cleanup actions on application close?
>
> I need to write out temporary objects and a footer to a file whenever
> the Application is closed.
>
> I've tried several approaches, but none of them produces any result
> when I "Force Quit" by hitting the red button within QtCreator.
>
> More specifically, I have tried to connect:
>
> QObject::connect(&myApplication, SIGNAL(aboutToQuit()),
> &myMainWindow, SLOT(closeFileSlot()));
>
> (note that I am using a QApplication rather than a QCoreApplication --
> I'm not sure if it makes a difference)
>
> and also
>
> connect(&myMainWindow, SIGNAL(destroy()), &myMainWindow,
> SLOT(closeFileSlot()));
>
> Neither of these approaches seems to successfully trigger the
> closeFileSlot() Any suggestions about what the right technique might be?
Hi
If you are doing this on Linux, I've made it like this:
in header:
#include <signal.h>
.......
public slots:
void terminate(bool fromSignal);
.....
};
extern "C" void terminate_wrapper(int dummy);
in cpp file:
in main class constructor:
GlobalVariable= (void*)this;
signal(SIGTERM,terminate_wrapper);
........
void MainClass::terminate(bool fromSignal) {
qDebug()<<"MainClass::terminate";
... close my services....
qApp->quit();
}
void terminate_wrapper(int dummy) {
MainClass *myApp=(MainClass*)GlobalVariable;
myApp->terminate(true);
}
So every time I hit red button in QtCreator it sends SIGTERM to application,
my wrapper catches it and I can do clean up.
regards
Marek
>
> Thanks
> Mitchell
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list