0

QTimer singleShot を使用して QDialog を開き、ステータス フラグを待つ必要があります。この変数が true の場合、続行します。

これは私のコードです

StatusFlag = FALSE;

void MainWindow::OpenWindow()
{
   qDebug("OpenWindow"); 
   NewGUI *gui=new NewGUI();
   gui->setModal(true);
   gui->exec();
}
void MainWindow::mWait(ulong milliSeconds)
{
    QEventLoop loop;
    QTimer::singleShot(milliSeconds, &loop, SLOT(quit()));
    loop.exec();
}

NewGUI コンストラクターで StatusFlag が TRUE に設定されている

QTimer::singleShot(0, this, SLOT(OpenWindow()));
while(StatusFlag == FALSE)
{
   //Wait until StatusFlag is TRUE.
   qDebug("Enter"); 
   mWait(1);
   qDebug("Exit");         
}

if(StatusFlag == TRUE)
{
   //Do something
   qDebug("Do something");  
}

現在の出力は

Enter 
OpenWindow

期待される出力は

Enter 
Exit
OpenWindow
Do something

行にコメントすると

QTimer::singleShot(0, this, SLOT(OpenWindow()));

次に、出力は

Enter 
Exit.. still continuing

何か提案はありますか?

4

1 に答える 1