PDA

View Full Version : Initialization code



Doug Broadwell
26th February 2007, 22:16
How can I get an initialization function to run once "return( app.exec )" is run?

Thanks

wysota
26th February 2007, 22:17
Either use a QTimer with a 0 timeout or run it before app.exec()

fullmetalcoder
27th February 2007, 11:48
How can I get an initialization function to run once "return( app.exec )" is run?

This does not make much sense... But I guess you probably meant once app.exec() is run and before it returns otherwise it wouldn't be an initialization function and would be as simple as that :

int retcode = app.exec();
someCleanupFunction();

However if you need initializations to be done the function as to be called after the QApplication object is created (or instanciations of painting related classes will fail) and, depending of whether they need an running event loop or not...

QApplication app;
staticInitFunction();

SomeDynamicInitObject dynamicInitObject;

QTimer::singleShot(0, &dynamicInitObject, SLOT( dynamicInitFunction() );

return app.exec();