#include <QApplication>#include <QThread>#include <QEvent>#include <QPushButton>#include <QDebug>//class Thread: public QThread{protected: void customEvent(QEvent*) { qDebug() << currentThread() << QApplication::instance()->thread(); QPushButton *pb = new QPushButton("!"); connect(pb, SIGNAL(clicked()), pb, SLOT(close())); pb->show(); }};//int main(int argc, char *argv[]){ QApplication app(argc, argv); Thread *thrd = new Thread(); thrd->start(); QApplication::postEvent(thrd, new QEvent(QEvent::User)); return app.exec();}
connect(pb, SIGNAL(clicked()), pb, SLOT(close()));