PDA

View Full Version : cleanup handler on application close



err23
14th August 2006, 13:50
hi, i have a small application which builds up a connection to a digital camera. To take a photo you have to set up "releaseMode". After the desired camera operations you have to part this releaseMode to finish clean. Otherwise you couldn't enter the releaseMode again.

so i need to do some cleanup operations. How to realize this? I thought about handling the QCoreApplication::aboutToQuit() signal, but it doesn't work yet.

Here my little test application

the receiver-class


class Nonce : public QObject
{
Q_OBJECT

public:
Nonce();
~Nonce();

public slots:
void quitter();

};


quitter method


void Nonce::quitter()
{
std::cout << " aboutToQuit emitted "<< std::endl << std::flush;
}


and a small main()



int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

Nonce foo;

QObject::connect(&a, SIGNAL(aboutToQuit()),
&foo, SLOT(quitter()));

return a.exec();
}


so.. when i "kill" the programm anyway the quitter method should be started, there i want leave the releaseMode.

any Ideas where are my faults? (yeah, I am quite new to Qt)

jacek
14th August 2006, 17:21
when i "kill" the programm anyway the quitter method should be started
When you kill your application, it is terminated immediately.

ball
16th August 2006, 04:53
Jacek, actually how to properly end a QCoreApplication to trigger aboutToQuit() signal, without pressing the 'X' button in right-top corner, or type Ctrl+C in keyboard? Both of these 2 actions will still KILL the QCoreApplication immediately.


When you kill your application, it is terminated immediately.

jacek
16th August 2006, 11:56
Jacek, actually how to properly end a QCoreApplication to trigger aboutToQuit() signal, without pressing the 'X' button in right-top corner, or type Ctrl+C in keyboard? Both of these 2 actions will still KILL the QCoreApplication immediately.
There are many ways. If it has a some form of CLI, then you have to implement proper command or if it works more like a daemon, you can use some IPC mechanism (like signals).

AFAIR Ctrl+C should send SIGINT and that 'X' button -- SIGTERM, so you can use your own handler that will send a custom event to your application object to make it invoke quit(). Of course this means that your console application must be event-driven.