Here's a good article on how to handle unix signals the Qt way (i.e via it's event loop):
http://qt-project.org/doc/qt-4.8/unix-signals.html HTH, -mandeep On Wed, Jul 10, 2013 at 5:53 PM, franki <fra...@franki.eu.org> wrote: > 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@qt-project.org > > http://lists.qt-project.org/mailman/listinfo/interest > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest