如何在函数中暂停程序,直到用户在窗体上执行某些操作
How to Pause program inside a function until a user does something on the form
我正在为我的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();
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- C++,系统无法执行指定的程序
- 使用C++中的模板和运算符重载执行矩阵运算
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 执行函数时导致崩溃的变量
- 无论条件是否为true,if总是在c++中执行
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 在C++中对T*类型执行std::move的意外行为
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如何在没有信号的情况下从C++执行QML插槽
- 如何确认我的constexpr表达式实际上已经在编译时执行
- C++17中的并行执行策略
- QML按钮点击功能执行顺序
- 程序在执行程序的其余部分之前退出
- 为什么catch中的代码没有被执行
- C++从其他 constexpr 创建 lambda 不能按顺序执行 Constexpr
- 我在哪里编写在退出 C++ 窗口窗体应用程序之前执行的代码部分
- 如何在函数中暂停程序,直到用户在窗体上执行某些操作
- 如何在qt构造函数完成执行前显示窗体
- 单击主窗体按钮时线程执行"stops"