View Full Version : subclassing QApplication
nupul
16th April 2006, 13:01
I have always used a QApplication object in the main function, as is used generally. What I am a bit curious about is this: when and why should one subclass QApplication?
Thanks
Nupul
jacek
16th April 2006, 13:28
You must subclass QApplication when you want to change the behavior of one or more of its virtual methods.
Here's an example: http://www.qtcentre.org/forum/showthread.php?p=10399#post10399
wysota
19th April 2006, 20:29
Or if you want to embed the whole application data into one object (for example to avoid global variables). You can then override QCoreApplication::instance() to return your "extended" pointer. And your main() can look like this then:
#include "myapplication.h"
int main(int argc, char **argv){
MyApplication app(argc, argv);
return app.exec();
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.