Blocked waiting for a asynchronous Qt signal

前端 未结 3 422
小蘑菇
小蘑菇 2020-12-24 07:22

I know, there are some similar questions to the following out there, but I couldn\'t find a concrete answer that helps me. So here\'s my problem:

I work on an applic

3条回答
  •  忘掉有多难
    2020-12-24 07:44

    The way to do this is to use nested event loops. You simply create your own QEventLoop, connect whatever signal you want to wait for to the loop's quit() slot, then exec() the loop. This way, once the signal is called, it will trigger the QEventLoop's quit() slot, therefore exiting the loop's exec().

    MyApp::MyApp(QWidget *parent) : ....
    {
        doSomeInits();
        {
            QEventLoop loop;
            loop.connect(configManager, SIGNAL(updateCompleted()), SLOT(quit()));
            configManager->updateConfigurations(); 
            loop.exec();
        }
        doReaminingInitsThatHadToWaitForConfigMgr();
    }
    

提交回复
热议问题