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;
}
}
}
I wrote in the PLC class to find all the QPushButton controls. I put five buttons on the UI. The children (), in PLC can not find the controls on the UI. The code is placed in the widget class and can be found successfully. The running result is shown in figure
.