In Qt, you should connect a (queued) signal emitted by your thread to a slot on a GUI thread object. The slot invocation is then processed by the event loop, just like the spontaneous events from e.g. user input.
From Maya Posch's excellent article on using QThread:
class Worker : public QObject {
Q_OBJECT
public:
Worker();
~Worker();
public slots:
void process();
signals:
void finished();
void error(QString err);
private:
// add your variables here
};
void Worker::process() {
// allocate resources using new here
qDebug("Hello World!");
emit finished();
}
In the GUI thread:
QThread* thread = new QThread;
Worker* worker = new Worker();
worker->moveToThread(thread);
connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
connect(thread, SIGNAL(started()), worker, SLOT(process()));
connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
The line you are interested in is
connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
Now go and read How To Really, Truly Use QThreads; The Full Explanation.