首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在函数中暂停程序直到用户在窗体上执行某些操作

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

Stack Overflow用户
提问于 2019-04-10 06:21:19
回答 1查看 121关注 0票数 0

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

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

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

代码语言:javascript
复制
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);

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-10 06:32:05

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

代码语言:javascript
复制
//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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55605925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档