The signal completed () is emitted due to a reason, but you will not catch it.
Here:
connect(_thread, SIGNAL(finished()), this, SLOT(OnFinished()));
Qt::QueuedConnection used because _thread and this (service) are in different threads.
By the end of the finished() _thread , the _thread event loop is _thread , so the signal will not be delivered to the slot.
You can explicitly use Qt::DirectConnection .
EDIT:
QTherad works as follows:
QThread::start() { emit started(); run(); emit finished(); } QThread::run() { eventloop->exec(); }
So, by the time the finished eventloop expires, it will already stop executing. When moving the service to the _thread event loop, the _thread event loop is.
Note that QObject itself does not have its own event loop. Event loops are created by dialog boxes, threads, and the application.
In fact, I would recommend QtConcurent::run in your simple case, since you are not processing the actual events in a new thread, but just run a single function.
source share