QT
QT 워커 스래드 예제
hellobird
2019. 2. 26. 22:03
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ss Worker : public QObject { Q_OBJECT public slots: void doWork(const QString ¶meter) { QString result; /* ... here is the expensive or blocking operation ... */ emit resultReady(result); } signals: void resultReady(const QString &result); }; class Controller : public QObject { Q_OBJECT QThread workerThread; public: Controller() { Worker *worker = new Worker; worker->moveToThread(&workerThread); connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); connect(this, &Controller::operate, worker, &Worker::doWork); connect(worker, &Worker::resultReady, this, &Controller::handleResults); workerThread.start(); } ~Controller() { workerThread.quit(); workerThread.wait(); } public slots: void handleResults(const QString &); signals: void operate(const QString &); }; | cs |
슬롯 & 시그널
https://doc.qt.io/archives/qt-4.8/signalsandslots.html
워커 스래드 사용법
https://doc.qt.io/qt-5/qthread.html#details
https://wiki.qt.io/QThreads_general_usage
qt 스레드 문서 한글
https://wiki.qt.io/QThreads_general_usage
https://doc.qt.io/archives/qt-4.8/threads-qobject.html#signals-and-slots-across-threads
Qwaitcondition 예제
https://doc.qt.io/qt-5/qtcore-threads-waitconditions-example.html