MySingleton.h
class MySingleton
{
protected:
fuiComponentManager() {}
~fuiComponentManager() {}
static MySingleton *s_pInstance()
{
if( s_pObjInstance == 0 )
s_pObjInstance = new MySingleton();
return s_pObjInstance;
}
bool Initialize()
{
pMyObj = new MyObj();
pMyObj->Initialize();
}
private:
static MySingleton *s_pObjInstance;
MyObj *pMyObj;
};
MySingleton *MySingleton::s_pObjInstance;
class MySingleton
{
protected:
fuiComponentManager() {}
~fuiComponentManager() {}
static MySingleton *s_pInstance()
{
if( s_pObjInstance == 0 )
s_pObjInstance = new MySingleton();
return s_pObjInstance;
}
bool Initialize()
{
pMyObj = new MyObj();
pMyObj->Initialize();
}
private:
static MySingleton *s_pObjInstance;
MyObj *pMyObj;
};
MySingleton *MySingleton::s_pObjInstance;
To copy to clipboard, switch view to plain text mode
MyObj.h
{
Q_OBJECT
public:
MyObj() {}
~MyObj() {}
bool Initialize()
{
connect(pTimer, SIGNAL(timeout()), this, SLOT(MySlot()));
pTimer->start(1000);
}
private slots:
void MySlot()
{
//Stuff
}
private:
};
class MyObj : public QObject
{
Q_OBJECT
public:
MyObj() {}
~MyObj() {}
bool Initialize()
{
pTimer = new QTimer(this);
connect(pTimer, SIGNAL(timeout()), this, SLOT(MySlot()));
pTimer->start(1000);
}
private slots:
void MySlot()
{
//Stuff
}
private:
QTimer *pTimer;
};
To copy to clipboard, switch view to plain text mode
main.cpp
#include "MySingleton.h"
int main(int argc, char *argv[])
{
fuiComponentManager::s_pInstance()->Initialize();
//Load gui and stuff here
}
#include "MySingleton.h"
int main(int argc, char *argv[])
{
fuiComponentManager::s_pInstance()->Initialize();
//Load gui and stuff here
}
To copy to clipboard, switch view to plain text mode
It's not exactly the same (left out some irrelevant lines and changed the class names), but that's pretty much it. As you see, it's not very complicated.
Bookmarks