Instead of implementing the instance pointer manually, use the
Singleton mixin.
// ==============================
// Core
// ==============================
-Core *Core::_instance{nullptr};
-
-Core *Core::instance()
-{
- return _instance;
-}
-
Core::Core()
+ : Singleton<Core>{this}
{
- if (_instance) {
- qWarning() << "Recreating core instance!";
- delete _instance;
- }
- _instance = this;
-
// Parent all QObject-derived attributes, so when the Core instance gets moved into another
// thread, they get moved with it
_server.setParent(this);
qDeleteAll(_connectingClients);
qDeleteAll(_sessions);
syncStorage();
- _instance = nullptr;
}
#include "message.h"
#include "oidentdconfiggenerator.h"
#include "sessionthread.h"
+#include "singleton.h"
#include "storage.h"
#include "types.h"
class AbstractSqlMigrationReader;
class AbstractSqlMigrationWriter;
-class Core : public QObject
+class Core : public QObject, public Singleton<Core>
{
Q_OBJECT
public:
- static Core *instance();
-
Core();
~Core() override;