C++ (Qt)// main.cpp#include "testapp.h"#include <QApplication>#include <QtDebug>#include <QTimer> int main(int argc, char *argv[]){// new QApplication(argc, argv); TestApp ta(argc, argv); QTimer::singleShot(1000, qApp, SLOT(quit())); return qApp->exec();}
C++ (Qt)// testapp.h#include <QObject> class TestApp : public QObject{ Q_OBJECT public: TestApp(int argc, char * argv[], QObject * parent = 0); ~TestApp(); private: static TestApp * instance_;};
C++ (Qt)// testapp.cpp#include "testapp.h"#include <QApplication>#include <QtDebug> TestApp * TestApp::instance_ = 0; TestApp::TestApp(int argc, char * argv[], QObject *parent) :QObject(parent){// qDebug() << "TestApp::TestApp()"; instance_ = this; new QApplication(argc, argv);} TestApp::~TestApp(){// qDebug() << "TestApp::~TestApp()"; delete qApp;}