{
private:
static MyWindow* instance;
protected:
public:
static MyWindow* getInstance()
{
if(!instance)
{
instance = new MyWindow();
}
return instance;
}
};
class MyWindow : public QMainWindow
{
private:
static MyWindow* instance;
protected:
MyWindow(QWidget* = NULL);
public:
static MyWindow* getInstance()
{
if(!instance)
{
instance = new MyWindow();
}
return instance;
}
};
To copy to clipboard, switch view to plain text mode
and in the cpp don't forget to initialize the static member to NULL.
Next, you can use this in other classes just by including the MyWindow header:
#include "MyWindow.h"
...
MyWindow* mainWindow = MyWindow::getInstance();
...
#include "MyWindow.h"
...
MyWindow* mainWindow = MyWindow::getInstance();
...
To copy to clipboard, switch view to plain text mode
Bookmarks