QT

QT concurrent를 이용한 쓰래드, 멤버 함수 포인터 예제

hellobird 2019. 2. 16. 19:52
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
Colored By Color Scripter™
 
 
#include <QCoreApplication>
 
#include <QThread>
#include <QtConcurrent>
 
static void worker(const QString &msg)
{
    qDebug() << __func__ << QThread::currentThread() << msg;
}
 
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
 
    qDebug() << __func__ << QThread::currentThread();
 
    QFutureWatcher<void> watcher;
    QObject::connect(&watcher, SIGNAL(finished()), &a, SLOT(quit()));
 
    QFuture<void> result = QtConcurrent::run(worker,
                                             QObject::tr("Hello, world"));
    watcher.setFuture(result);
 
    return a.exec();
}
cs



QT += concurrent 


참고 :http://lvzuufx.blogspot.com/2015/10/qt_21.html


QT document

https://doc.qt.io/qt-5/qtconcurrent-index.html

l