大佬教程收集整理的这篇文章主要介绍了QVector 使用 Qt 按名称查找 QPushButton,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个创建 QPushbuttons 的函数
voID MainWindow::createbutton(qframe *parent,int x,int y,int w,int h,QString txt) {
QPushbutton* button = new QPushbutton(parent);
button->setGeometry(x,y,w,h);
button->setText(txt);
button->setobjectname("pushbutton_" + txt);
vecbuttons.push_BACk(button);
}
在主窗口构造函数中,我想连接按钮,因此我必须找到按钮。
有通用的搜索算法吗?@H_489_12@
即使您可以通过名称找到对象,例如:
QPushButton *button = parentWidget->findChild<QPushButton *>("pushButton_" + txt);
这种方法的缺点是您需要记录按钮的命名方式...
如果你按照评论中的建议去做会更好,在createButton方法中连接
void MainWindow::createButton(QFrame *parent,int x,int y,int w,int h,QString txt) {
QPushButton* button = new QPushButton(parent);
button->setGeometry(x,y,w,h);
button->setText(txt);
button->setObjectName("pushButton_" + txt);
connect(button,somesignal,this,someSlot); //here
vecButtons.push_BACk(button);
}
以上是大佬教程为你收集整理的QVector 使用 Qt 按名称查找 QPushButton全部内容,希望文章能够帮你解决QVector 使用 Qt 按名称查找 QPushButton所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。