void PLC::SearchControl()
{
QObjectList list =children() ;
qDebug() << list.length() << endl;
QPushButton *b;
foreach (QObject *obj, list)
{
b = qobject_cast<QPushButton*>(obj);
if(b)
{
PushButtonStr.append( b->text());
qDebug() << b->text() << endl;
}
}
}
我在PLC类中写的查找所有QPushButton控件,UI上我放了5个按钮,PLC中的children(), 并不能找到UI上的控件,代码放在widget类中,能成功找到,运行结果如图