如何在函数内暂停程序,直到用户在表单上执行某些操作
How to Pause program inside a function until a user does something on the form
我正在为我的 C++ Class 开发一个项目,我们正在开发一个包含 AI 和用户的扑克程序。使用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();
我正在为我的 C++ Class 开发一个项目,我们正在开发一个包含 AI 和用户的扑克程序。使用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();