轉載:https://blog.csdn.net/hp_cpp/article/details/82715454
(1)在代碼中,動態創建的一些控件,先通過setObjectName(“XXX”);
用QDesigner創建的界面,就已經設置了setObjectName
(2)再通過findChild
QLabel *macLabel = new QLabel(this); macLabel->setObjectName("mac"); //查找這個控件的時候 QLabel *macLabel = yourWidget->findChild<QLabel*>("mac"); qDebug() << macLabel->text();
參考:
(1)https://blog.csdn.net/weixin_38293850/article/details/80251446
(2)https://www.2cto.com/kf/201712/704566.html