Results 1 to 4 of 4

Thread: Enumerate

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Enumerate

    Is it possible to enumerate the gourpBox object?
    That is , I would like to meake a loop which iterate over all the object of a goupBox, an I need the goupBox object's count.

  2. #2
    Join Date
    May 2007
    Posts
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enumerate

    I am not sure is it what you want but check children function. It returns a list of all children so you can in easy way to find out how many objects your groupbox has.

  3. #3
    Join Date
    May 2007
    Posts
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Post Re: Enumerate

    Here you are an example code:

    Qt Code:
    1. QGroupBox *groupBox = new QGroupBox(tr("E&xclusive Radio Buttons"));
    2. groupBox->setCheckable(true);
    3. groupBox->setChecked(false);
    4. QRadioButton *radio1 = new QRadioButton(tr("Rad&io button 1"));
    5. QRadioButton *radio2 = new QRadioButton(tr("Radi&o button 2"));
    6. QRadioButton *radio3 = new QRadioButton(tr("Radio &button 3"));
    7. radio1->setChecked(true);
    8. QCheckBox *checkBox = new QCheckBox(tr("Ind&ependent checkbox"));
    9. checkBox->setChecked(true);
    10.  
    11. QVBoxLayout *vbox = new QVBoxLayout;
    12. vbox->addWidget(radio1);
    13. vbox->addWidget(radio2);
    14. vbox->addWidget(radio3);
    15. vbox->addWidget(checkBox);
    16. vbox->addStretch(1);
    17. groupBox->setLayout(vbox);
    18.  
    19. const QList<QObject*> children = groupBox->children();
    20.  
    21. qDebug() << "Number of children: " << children.count();
    22.  
    23. for(QList<QObject*>::const_iterator cit = children.begin();
    24. cit != children.end();++cit)
    25. {
    26. qDebug() << "Child: " << (*cit)->metaObject()->className();
    27. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Enumerate

    Thank you very much. I will try it.
    G

Similar Threads

  1. Enumerate processes using Qt
    By Ben.Hines in forum Qt Programming
    Replies: 5
    Last Post: 14th February 2006, 16:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.