diff options
-rw-r--r-- | controller.cxx | 16 | ||||
-rw-r--r-- | controller.hxx | 18 | ||||
-rw-r--r-- | kelakon.pro | 6 | ||||
-rw-r--r-- | main.cxx | 9 |
4 files changed, 40 insertions, 9 deletions
diff --git a/controller.cxx b/controller.cxx new file mode 100644 index 0000000..d1271b9 --- /dev/null +++ b/controller.cxx @@ -0,0 +1,16 @@ +#include "worker.hxx" +#include "controller.hxx" + +Controller::Controller() +{ + Worker* worker = new Worker{}; + worker->moveToThread(&thread); + connect(&thread, &QThread::finished, worker, &QObject::deleteLater); + thread.start(); +} + +Controller::~Controller() +{ + thread.quit(); + thread.wait(); +} diff --git a/controller.hxx b/controller.hxx new file mode 100644 index 0000000..e293ec4 --- /dev/null +++ b/controller.hxx @@ -0,0 +1,18 @@ +#ifndef CONTROLLER_HXX +#define CONTROLLER_HXX + +#include <QThread> + +class Controller : public QObject +{ + Q_OBJECT + + public: + Controller(); + ~Controller(); + + private: + QThread thread; +}; + +#endif // CONTROLLER_HXX diff --git a/kelakon.pro b/kelakon.pro index 34a2948..5df2f8e 100644 --- a/kelakon.pro +++ b/kelakon.pro @@ -5,12 +5,14 @@ QT += \ debug: DEFINES += DEBUG HEADERS += \ + user.hxx \ worker.hxx \ - user.hxx + controller.hxx SOURCES += \ - worker.cxx \ user.cxx \ + worker.cxx \ + controller.cxx \ main.cxx RESOURCES += kelakon.qrc @@ -1,8 +1,7 @@ #include <QGuiApplication> #include <QQmlApplicationEngine> -#include <QThread> #include "user.hxx" -#include "worker.hxx" +#include "controller.hxx" int main(int argc, char* argv[]) { @@ -10,10 +9,6 @@ int main(int argc, char* argv[]) QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - Worker worker{}; - QThread thread; - worker.moveToThread(&thread); - qmlRegisterSingletonType<User>("id.co.darapsa.kelakon.user", 0, 1, "User", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* { Q_UNUSED(engine) Q_UNUSED(scriptEngine) @@ -23,7 +18,7 @@ int main(int argc, char* argv[]) }); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - thread.start(); + Controller controller{}; return app.exec(); } |