29 lines
710 B
C++
29 lines
710 B
C++
#pragma once
|
|
#include <QDebug>
|
|
namespace YSG {
|
|
template <typename T>
|
|
class Singleton_Widget {
|
|
public:
|
|
static T* instance() {
|
|
if (!mInstance) {
|
|
qInfo() << "error SingletonWidget 未创建" << mInstance;
|
|
}
|
|
return mInstance;
|
|
}
|
|
Singleton_Widget() {
|
|
if (mInstance) {
|
|
qInfo() << "error SingletonWidget 重复创建" << mInstance;
|
|
}
|
|
mInstance = static_cast<T*>(this);
|
|
}
|
|
virtual ~Singleton_Widget() {}
|
|
Singleton_Widget(T&&) = delete;
|
|
Singleton_Widget(const T&) = delete;
|
|
void operator=(const T&) = delete;
|
|
protected:
|
|
static T* mInstance;
|
|
};
|
|
template <typename T>
|
|
T* Singleton_Widget<T>::mInstance = nullptr;
|
|
}
|