Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Correct way to iterate over a QObjectList?

Correct way to iterate over a QObjectList?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HenrytheEighth
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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) {
           obj->xxx;
          }
      
      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved