天天看点

Qt5.9中根据控件ObjectName查找该控件(查找按钮控件对象Object::findChild())(按钮QPushbutton)

1.1已经知道一个QPushbutton的objectName,可以根据该objectName查找到对应的QPushbutton按钮对象。具体实现函数是:

findChild(const QString &aName = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
           

1.2下面是实现的关键代码:

    QString objectNameBtn = sender()->objectName();
    QPushButton *tempButton = this->findChild<QPushButton *>(objectNameBtn);
           

其中,tempButton获得了该objectName对应控件的入口地址。

参考内容:

https://blog.csdn.net/liang19890820/article/details/52118210(重点参考)

http://blog.chinaunix.net/uid-12664992-id-129943.html

https://blog.csdn.net/fanyun_01/article/details/78907276

继续阅读