等待,直到按下按钮(QT)
Wait until button pressed(QT)
这是我在SO^_^上的第一篇文章
我正在尝试用QT框架实现一个字母争夺游戏。主要部分已经完成了,但现在我惊呆了——我不知道如何制作程序来等待游戏中的按钮被按下。
请帮我。提前谢谢
这是我游戏周期的伪代码:
//initialize grid, score, time
// accept words until timer expires
while (true) {
// draw the current state of the grid
// log board
// get current time
// report score
// check for game's end
// report time remaining
// prompt for word and converting it to char*
//HOW TO WAIT UNTILL BUTTON PRESSED????!!!!
// check whether to scramble grid
// or to look for word on grid and in dictionary
}
附言:由于这是我在这里的第一篇文章,我将感谢你对如何更正确地撰写问题的任何建议。
在我看来,您缺少的是Qt是基于事件驱动编程的。Qt提供小部件/对象,如按钮、窗口、控制器等,您可以向用户显示。例如,QPushButton对象能够接收各种事件,例如单击鼠标按钮或按下键盘键等。
对于事件,Qt提供用于接收这些事件并对其作出反应的槽/信号机制。因此,举个例子,在QPushButton的情况下,有一个叫做"按下"的信号。当用户点击按钮时,就会发出按下的信号。作为开发人员,您可以将按下的信号连接到插槽,这是您定义的函数。
例如,在从QObject派生的名为MyClass的类中:-
QPushButton button("Select"); // create a QPushButton object
connect(button, SIGNAL(pressed()), this, SLOT(buttonPressed()));
connect语句将按钮的"按下"信号连接到名为"buttonPressed"的插槽函数。然后您可以定义该函数:-
void MyClass::buttonPressed()
{
// handle the button pressed event....
}
因此,实际上你没有任何等待按钮按下的调用,因为框架和它的架构是这样设计的,你不应该把所有东西都放在一个while(true)循环中。
相关文章:
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- Qt自定义QPush按钮未显示在布局上
- Qt中来自不同功能的按钮引用
- 按钮悬停在 QT 中垂直布局的选项卡小部件中不起作用
- 如何通过拖动鼠标QT检查按钮?鼠标移动事件
- 更改 QT 中按钮的颜色
- 以编程方式在任何按钮上突出显示 Qt 鼠标悬停按钮
- QT-如何通过按下按钮从子窗口小部件返回到父窗口小部件
- 使每个按钮的QT设计器窗体不同
- QT - 连接 Qml 按钮 单击到 Cpp 构造函数
- 如何将QLabel放入切换按钮Qt c ++中
- 单击"推送"按钮应使用Qt C++在不同的窗口中显示绘图
- Qt按钮按下增量
- Qt创建一个左箭头样式的按钮
- 无法增加 QToolButton 的大小(按钮样式设置为 Qt::ToolButtonTextBesideIcon)
- Qt - 右键单击时编辑按钮文本
- 将类功能连接到按钮.(QT C )
- 当单击旁边的按钮[qt]时,如何动态创建标签
- 等待,直到按下按钮(QT)
- 没有这样的插槽按钮QT