diff options
author | Anatasof Wirapraja <anatasof.wirapraja@gmail.com> | 2019-08-29 17:50:57 +0700 |
---|---|---|
committer | Anatasof Wirapraja <anatasof.wirapraja@gmail.com> | 2019-08-29 17:50:57 +0700 |
commit | 933fa1019041966c908967567523e6f972da8186 (patch) | |
tree | 2e8316ef83e479d6b396293e06509771eaecffbf | |
parent | eeacda8d7edf463738d4527c377bc44e869a02c6 (diff) | |
parent | c8891b50d1f30c7c07bf96f8eaf2e1002ce573b8 (diff) |
Merge branch 'development' of ssh://darapsa.co.id/usr/local/git/kelakon into development
* 'development' of ssh://darapsa.co.id/usr/local/git/kelakon:
Set up a way for the thread to quit
Renamed NetworkWorker to just Worker
-rw-r--r-- | controller.cxx | 16 | ||||
-rw-r--r-- | controller.hxx | 18 | ||||
-rw-r--r-- | kelakon.pro | 8 | ||||
-rw-r--r-- | main.cxx | 9 | ||||
-rw-r--r-- | networkworker.cxx | 13 | ||||
-rw-r--r-- | networkworker.hxx | 14 | ||||
-rw-r--r-- | worker.cxx | 13 | ||||
-rw-r--r-- | worker.hxx | 14 |
8 files changed, 68 insertions, 37 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 388027c..5df2f8e 100644 --- a/kelakon.pro +++ b/kelakon.pro @@ -5,12 +5,14 @@ QT += \ debug: DEFINES += DEBUG HEADERS += \ - networkworker.hxx \ - user.hxx + user.hxx \ + worker.hxx \ + controller.hxx SOURCES += \ - networkworker.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 "networkworker.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; - NetworkWorker 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(); } diff --git a/networkworker.cxx b/networkworker.cxx deleted file mode 100644 index 3487d4c..0000000 --- a/networkworker.cxx +++ /dev/null @@ -1,13 +0,0 @@ -#include "rtclient.h" -#include "networkworker.hxx" - -NetworkWorker::NetworkWorker(QObject* parent) : - QObject{parent} -{ - rtclient_init(); -} - -NetworkWorker::~NetworkWorker() -{ - rtclient_cleanup(); -} diff --git a/networkworker.hxx b/networkworker.hxx deleted file mode 100644 index 05124d5..0000000 --- a/networkworker.hxx +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef NETWORKWORKER_HXX -#define NETWORKWORKER_HXX - -#include <QObject> - -class NetworkWorker : public QObject -{ - Q_OBJECT - public: - explicit NetworkWorker(QObject* parent = nullptr); - virtual ~NetworkWorker(); -}; - -#endif // NETWORKWORKER_HXX diff --git a/worker.cxx b/worker.cxx new file mode 100644 index 0000000..8c915f8 --- /dev/null +++ b/worker.cxx @@ -0,0 +1,13 @@ +#include "rtclient.h" +#include "worker.hxx" + +Worker::Worker(QObject* parent) : + QObject{parent} +{ + rtclient_init(); +} + +Worker::~Worker() +{ + rtclient_cleanup(); +} diff --git a/worker.hxx b/worker.hxx new file mode 100644 index 0000000..cdb2811 --- /dev/null +++ b/worker.hxx @@ -0,0 +1,14 @@ +#ifndef WORKER_HXX +#define WORKER_HXX + +#include <QObject> + +class Worker : public QObject +{ + Q_OBJECT + public: + explicit Worker(QObject* parent = nullptr); + virtual ~Worker(); +}; + +#endif // WORKER_HXX |