An event loop is started by calling exec(), for example QCoreApplication::exec(). Pending events can be processed (once) using processEvents().
@
class SignalTest : public QObject
{
Q_OBJECT
public:
void test()
{
qDebug() << Q_FUNC_INFO << QThread::currentThread() << thread();
emit signal(0);
}
signals:
void signal(int parameter);
public slots:
void slot(int parameter)
{
Q_UNUSED(parameter);
qDebug() << Q_FUNC_INFO << QThread::currentThread() << thread();
}
};
int main(int argc, char *argv[])
{
QCoreApplication application(argc, argv);
qDebug() << Q_FUNC_INFO << QThread::currentThread();
SignalTest signalTest;
signalTest.connect(&signalTest, SIGNAL(signal(int)), &signalTest, SLOT(slot(int)), Qt::QueuedConnection);
QtConcurrent::run(&signalTest, &SignalTest::test);
return application.exec(); // run event loop for main thread
}
@
[quote author="vishwajeet" date="1322117812"]For this example it is fine to miss few signals.[/quote]
Just make sure you are aware of it. Another pitfall is the following restriction of QtConcurrent::run():
[quote]Note that the QFuture returned by QtConcurrent::run() does not support canceling, pausing, or progress reporting. The QFuture returned can only be used to query for the running/finished status and the return value of the function.[/quote]
This means, that if your method never returns (as in your case, while(1) { ... }) you will have to provide a mechanism to break, otherwise you won't be able to terminate the thread.