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