How to traverse QCheckBox in QGridLayout in qt5

multiple checkbox have been added to one gridlayout.
how to traverse all box under layout and modify state?
there is no response using the following methods

QLayout *layout = ui->gridLayout->layout();
  

foreach(QObject *obj, layout->children())
{
     QCheckBox *chkbox = qobject_cast<QCheckBox *>(obj);
     qDebug()<<"name:"<<chkbox->objectName();
 }
Qt5
Apr.12,2022
Menu