Important: Please read the Qt Code of Conduct -

Correct way to iterate over a QObjectList?

  • I'm trying to iterate over all the Widgets in a QObject. I've tried to do this by getting the list with:

    QObjectList the_children = this->children();
    QListIterator<QObject> iter(the_children);

    I get an error from the IDE saying that the_children isn't a QList.
    What would be the proper way to iterate over the children of a QObject?

    Thanks in advance for your help!

  • Lifetime Qt Champion

    Hi and welcome to the forums
    You can use findChildren to find all.
    Here is sample to find all QObjects.

    QList<QObject*> list = theobjecttosearch->findChildren<QObject*>();
        foreach (auto obj, list) {

Log in to reply