Results 1 to 9 of 9

Thread: How to iterate through QButtonGroup's buttons?

  1. #1
    Join Date
    Jan 2006
    Location
    Sofia, Bulgaria
    Posts
    24
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default How to iterate through QButtonGroup's buttons?

    Hi there,
    Does anyone know how can I easily iterate through QButtonGroup's buttons?

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to iterate through QButtonGroup's buttons?

    Obtain a list of all childs of your QButtonGroup:

    http://doc.trolltech.com/4.1/qobject.html#children

    Have a for..each-loop iterate over all of them and check wether they are subclasses of QAbstractButton (Qt4) or QButton (Qt3) by using either qt_cast in Qt4 or http://doc.trolltech.com/4.1/qobject.html#inherits
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to iterate through QButtonGroup's buttons?

    And check their group() value.

  4. #4
    Join Date
    Jan 2006
    Location
    Sofia, Bulgaria
    Posts
    24
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to iterate through QButtonGroup's buttons?

    I've done it in a more clear way: every button I put in the button group I put also in a QPtrList. But that's as dumb as iterating all the children of the button group. I think it would be very good to have an iterator class for the QButtonGroup class.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to iterate through QButtonGroup's buttons?

    ...which would iterate over its children thus the effect would be the same and it would slow the code.

  6. #6
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to iterate through QButtonGroup's buttons?

    I don't get it
    Doesn't the QButtonGroup have
    Qt Code:
    1. QList<QAbstractButton *> QButtonGroup::buttons () const
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QList<QAbstractButton *> list = buttonGroup->buttons();
    2. ...
    3. foreach ( QAbstractButton *pButton, list){
    4. // .......
    5. }
    6. // Check !!!
    7. delete list; // Not Sure Please Check ??
    To copy to clipboard, switch view to plain text mode 

    wont't this Do ?

    One More do we need to Delete the List ?
    We can't solve problems by using the same kind of thinking we used when we created them

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to iterate through QButtonGroup's buttons?

    Quote Originally Posted by sunil.thaha
    One More do we need to Delete the List ?
    How? It's not a pointer.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to iterate through QButtonGroup's buttons?

    Quote Originally Posted by sunil.thaha
    I don't get it
    Doesn't the QButtonGroup have
    Qt Code:
    1. QList<QAbstractButton *> QButtonGroup::buttons () const
    To copy to clipboard, switch view to plain text mode 

    wont't this Do ?
    The question concerned Qt3 and not Qt4 (as you may notice in the header, the author uses Qt3 only) and QButtonGroup::buttons() is not present there.

  9. #9
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to iterate through QButtonGroup's buttons?

    There Again,
    Some one forgets to See the Version
    We can't solve problems by using the same kind of thinking we used when we created them

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.