From 16bc24b796de76ec1a5fa66dcfe2129a2b02d370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Sat, 7 Sep 2019 15:40:47 +0800 Subject: Changed controller's parent to the engine to give more flexibility --- controller.cxx | 11 ++++++++--- kelakon.pro | 2 ++ main.cxx | 21 ++++++++------------- user.hxx | 1 + 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/controller.cxx b/controller.cxx index 4e518f4..757d475 100644 --- a/controller.cxx +++ b/controller.cxx @@ -1,14 +1,19 @@ +#include #include "worker.hxx" #include "controller.hxx" -Controller::Controller(QObject* parent) : - QObject{parent} +Controller::Controller(QObject* parent) : QObject{parent} { Worker* worker = new Worker{}; worker->moveToThread(&thread); connect(&thread, &QThread::finished, worker, &QObject::deleteLater); - connect(parent, SIGNAL(logIn(QString, QString)), + + auto engine = dynamic_cast(parent); + auto rootObjects = engine->rootObjects(); + auto appWindow = rootObjects[0]; + connect(appWindow, SIGNAL(logIn(QString, QString)), worker, SLOT(logIn(QString, QString))); + thread.start(); } diff --git a/kelakon.pro b/kelakon.pro index 8b9ead1..847864d 100644 --- a/kelakon.pro +++ b/kelakon.pro @@ -2,6 +2,8 @@ QT += \ quickcontrols2 \ svg +*-g++: QMAKE_CXXFLAGS += -std=gnu++17 +*-clang: QMAKE_CXXFLAGS += -std=c++17 debug: DEFINES += DEBUG HEADERS += \ diff --git a/main.cxx b/main.cxx index 9437396..479d302 100644 --- a/main.cxx +++ b/main.cxx @@ -10,21 +10,16 @@ int main(int argc, char* argv[]) QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - - qmlRegisterSingletonType("id.co.darapsa.kelakon.user", 0, 1, "User", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* { - Q_UNUSED(engine) - Q_UNUSED(scriptEngine) - return new User{}; - }); - + User::typeId = qmlRegisterSingletonType("id.co.darapsa.kelakon.user" + , 0, 1, "User" + , [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* { + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + return new User{}; + }); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - auto rootObjects = engine.rootObjects(); - if (rootObjects.isEmpty()) return -1; - - auto appWindow = rootObjects[0]; - Controller controller{appWindow}; + Controller controller{&engine}; TaskList taskList; engine.rootContext()->setContextProperty("taskList", &taskList); - return app.exec(); } diff --git a/user.hxx b/user.hxx index 18dd176..3bb9b7e 100644 --- a/user.hxx +++ b/user.hxx @@ -32,6 +32,7 @@ class User : public QObject m_isLoggedIn{isLoggedIn} {} ~User() {} + inline static int typeId; QString const& name() const { return m_name; } QString const& password() const { return m_password; } -- cgit v1.2.3