如何在函数中暂停程序,直到用户在窗体上执行某些操作

How to Pause program inside a function until a user does something on the form

本文关键字:窗体 执行 用户 操作 函数 暂停 程序      更新时间:2023-10-16

我正在为我的C++班做一个项目,我们正在与人工智能和用户一起做一个扑克程序。使用 QT 进行开发。

我需要做的是在函数 DECISION(( 中,如果玩家不是 AI,程序会暂停,直到用户点击按钮进行折叠、调用或提升。

基本上,我需要在执行函数的过程中暂停程序,直到用户按下按钮。然后它将继续函数的其余部分

if(Player[pp].ai == true){
    //A bunch of code for AI decision making for folding, calling, raising.
}
else{ //If Player is NOT an AI
    ENABLEUSERINPUT(true);
   //Need to pause program here until the user has done something to the GUI
   ENABLESERINPUT(false);
}
可以使用

QEventLoop等待用户输入 例如,单击按钮将退出事件循环。

//Need to pause program here until the user has done something to the GUI
QEventLoop oLoop;
// user click on button will release the event loop.
connect(pYoutrBtn , &QPushButton::clicked,
        &oLoop,     &QEventLoop::quit);
// wait.
oLoop.exec();