如何以编程方式单击QPushButton [英] How to programmatically click a QPushButton

查看:68
本文介绍了如何以编程方式单击QPushButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Qt.我在通过Qt Creator添加的页面上有一个按钮.它连接到方法 void MyPage :: on_startButton_clicked().

I am using Qt. I have a button in the page added via the Qt Creator. It is connected to the method void MyPage::on_startButton_clicked().

我要以编程方式单击此按钮.我尝试了 ui-> startButton-> clicked(),它给出了

I want to programmatically click this button. I tried ui->startButton->clicked(), it gives,

错误C2248:'QAbstractButton :: clicked':无法访问在类'QAbstractButton'中声明的受保护成员

error C2248: 'QAbstractButton::clicked' : cannot access protected member declared in class 'QAbstractButton'

请帮助.谢谢!

推荐答案

使用 QAbstractButton:: animateClick() :

QPushButton* startButton = new QPushButton("Start");
startButton->animateClick();

这篇关于如何以编程方式单击QPushButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆