#include <QtGui/QApplication>#include <QThread>#include <QDebug>#include <QTimer>#include <QDialog>class Dialog : public QDialog { Q_OBJECTpublic: explicit Dialog(QWidget *parent = 0) : QDialog(parent) { }};class Tester : public QObject { Q_OBJECTprotected: int i; QTimer timer;public: Tester(QObject* parent = NULL) : QObject(parent) , i(0) { timer.setInterval(3000); connect(&timer,SIGNAL(timeout()),this,SLOT(RunDialog()),Qt::QueuedConnection); timer.start(); }public slots: void RunDialog() { qDebug()<<"run in "<<QThread::currentThreadId(); Dialog w; w.setWindowTitle(QString("Dialog %1 from %2").arg(i++).arg(QString::number((long)QThread::currentThreadId(),16))); w.exec(); qDebug()<<"Dialog \""<<w.windowTitle()<<"\" closed"; }};int main(int argc, char *argv[]){ QApplication a(argc, argv); a.setQuitOnLastWindowClosed(false); qDebug()<<"main thread "<<QThread::currentThreadId(); Tester tester; return a.exec();}#include "main.moc"