34 lines
728 B
C++
34 lines
728 B
C++
#pragma once
|
|
#include <QDebug>
|
|
|
|
namespace Flex_Qt {
|
|
|
|
template <typename T>
|
|
class Singleton_Widget {
|
|
public:
|
|
static T* instance() {
|
|
if (!instance_)
|
|
qInfo() << "error Singleton_Widget not created" << instance_;
|
|
return instance_;
|
|
}
|
|
|
|
Singleton_Widget() {
|
|
if (instance_)
|
|
qInfo() << "error Singleton_Widget duplicated" << instance_;
|
|
instance_ = static_cast<T*>(this);
|
|
}
|
|
|
|
virtual ~Singleton_Widget() = default;
|
|
Singleton_Widget(T&&) = delete;
|
|
Singleton_Widget(const T&) = delete;
|
|
void operator=(const T&) = delete;
|
|
|
|
protected:
|
|
static T* instance_;
|
|
};
|
|
|
|
template <typename T>
|
|
T* Singleton_Widget<T>::instance_ = nullptr;
|
|
|
|
} // namespace Flex_Qt
|