mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-07-06 10:45:26 +08:00
update
This commit is contained in:
@ -1,25 +1,18 @@
|
||||
#ifndef SINGLETON_H
|
||||
#define SINGLETON_H
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
/**
|
||||
* @brief The Singleton class
|
||||
*/
|
||||
template <typename T>
|
||||
class Singleton {
|
||||
public:
|
||||
static T* getInstance();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY_MOVE(Singleton)
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T* Singleton<T>::getInstance() {
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
static T* instance = nullptr;
|
||||
if (instance == nullptr) {
|
||||
instance = new T();
|
||||
}
|
||||
static T* instance = new T();
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -31,10 +24,4 @@ private: \
|
||||
return Singleton<Class>::getInstance(); \
|
||||
}
|
||||
|
||||
#define HIDE_CONSTRUCTOR(Class) \
|
||||
private: \
|
||||
Class() = default; \
|
||||
Class(const Class& other) = delete; \
|
||||
Q_DISABLE_COPY_MOVE(Class);
|
||||
|
||||
#endif // SINGLETON_H
|
||||
|
Reference in New Issue
Block a user