mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-01-23 04:14:35 +08:00
fix: [singleton] Fixed an issue with the Singleton class redefinition
fix #564
This commit is contained in:
parent
29686d07ba
commit
cb4ec62c1e
@ -13,6 +13,6 @@ class AppInfo : public QObject {
|
||||
explicit AppInfo(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(AppInfo)
|
||||
EXAMPLESINGLETON(AppInfo)
|
||||
[[maybe_unused]] Q_INVOKABLE void testCrash();
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ private:
|
||||
void templateToFile(const QString &source, const QString &dest, Args &&...args);
|
||||
|
||||
public:
|
||||
SINGLETON(InitializrHelper)
|
||||
EXAMPLESINGLETON(InitializrHelper)
|
||||
~InitializrHelper() override;
|
||||
[[maybe_unused]] Q_INVOKABLE void generate(const QString &name, const QString &path);
|
||||
Q_SIGNAL void error(const QString &message);
|
||||
|
@ -144,7 +144,7 @@ private:
|
||||
explicit Network(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(Network)
|
||||
EXAMPLESINGLETON(Network)
|
||||
|
||||
static Network *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) {
|
||||
return getInstance();
|
||||
|
@ -15,7 +15,7 @@ private:
|
||||
explicit SettingsHelper(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(SettingsHelper)
|
||||
EXAMPLESINGLETON(SettingsHelper)
|
||||
~SettingsHelper() override;
|
||||
void init(char *argv[]);
|
||||
Q_INVOKABLE void saveDarkMode(int darkModel) {
|
||||
|
@ -14,7 +14,7 @@ private:
|
||||
[[maybe_unused]] explicit TranslateHelper(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(TranslateHelper)
|
||||
EXAMPLESINGLETON(TranslateHelper)
|
||||
~TranslateHelper() override;
|
||||
void init(QQmlEngine *engine);
|
||||
|
||||
|
@ -4,22 +4,22 @@
|
||||
* @brief The Singleton class
|
||||
*/
|
||||
template <typename T>
|
||||
class Singleton {
|
||||
class ExampleSingleton {
|
||||
public:
|
||||
static T *getInstance();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T *Singleton<T>::getInstance() {
|
||||
T *ExampleSingleton<T>::getInstance() {
|
||||
static T *instance = new T();
|
||||
return instance;
|
||||
}
|
||||
|
||||
#define SINGLETON(Class) \
|
||||
#define EXAMPLESINGLETON(Class) \
|
||||
private: \
|
||||
friend class Singleton<Class>; \
|
||||
friend class ExampleSingleton<Class>; \
|
||||
\
|
||||
public: \
|
||||
static Class *getInstance() { \
|
||||
return Singleton<Class>::getInstance(); \
|
||||
return ExampleSingleton<Class>::getInstance(); \
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user