void MyThread::run(){ ... // need to stop thread and show dialog QWaitCondition condition; QMutex mutex; qApp->postEvent( object_from_main_thread, MyEvent( &condition ) ); { QMutexLocker locker( &mutex ); condition.wait( &mutex ); } // now dialog closed}bool ObjectFromMainThread::event( QEvent * e ){ if ( e->type() == MY_EVENT ) { MyEvent * me = static_cast<MyEvent*>( e ); show_my_dialog(); me->condition->wakeAll(); return true; } // ...}
void MyThread::run(){ ... // need to stop thread and show dialog QWaitCondition condition; QMutex mutex; MyEvent ev( &condition ) qApp->postEvent( object_from_main_thread, ev); { QMutexLocker locker( &mutex ); condition.wait( &mutex ); } //Получаем код возврата: ... = ev->dialogResult();}bool ObjectFromMainThread::event( QEvent * e ){ if ( e->type() == MY_EVENT ) { MyEvent * me = static_cast<MyEvent*>( e ); int dlg_res = show_my_dialog(); //Запоминаем код в MyEvent me->setDialogResult(dlg_res); me->condition->wakeAll(); return true; } // ...}
struct ReturnData{ int code; QString message;};ReturnData data;qApp->postEvent( object_from_main_thread, new MyEvent( &data, &condition ) );...if ( data.code == 123 ) qDebug() << "Dialog returned message: " << data.message;
qApp->postEvent( object_from_main_thread, MyEvent( &condition ) );