Results 1 to 6 of 6

Thread: How to use for loop to check multiple number of objects

  1. #1
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default How to use for loop to check multiple number of objects

    Hi,

    I have created 32 chechkboxes in one of my program and given unique name for each object by incrementing the value of 1,i.e name of 1st checkbox is ch_1 and 2nd checkbox is ch_2 and so on.
    I want to check weather all the checkboxes were selected or not by using for loop is it possible to use the for loop.If there is a chance please help me

    Thanks in advance,

    Rohith.G

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use for loop to check multiple number of objects

    Create a list or vector with the pointers of these checkboxes and iterate over that container.
    Or use QObject::findChildren() on a common ancestor with a regular expression matching your name definitions (assuming those are the checkboxes' QObject names)

    Cheers,
    _

  3. #3
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to use for loop to check multiple number of objects

    Hi Anda_skoa,

    First of all thanks for replying for me i have tried by following your guidance,but i was not able to execute i may done wrong some where.
    I have created the checkboxes in the Qt creator and when i am trying to use the find children by using the following statement written below
    QCheckBox *box = parentWidget->findChild<QCheckBox *>("ch_1");

    But while compiling this is producing error
    "error: invalid use of member (did you forget the '&' ?)
    error: base operand of '->' is not a pointer"


    Please guide me

    Thanks & Regards,
    Rohith.G

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use for loop to check multiple number of objects

    Do you have a variable called "parentWidget"?
    Or are you trying to use QWidget::parentWidget() and forgot the parentheses?

    And just to be sure: you are aware that findChild() will only retrieve one widget, right?
    That you could directly access via the "ui" pointer.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    gunturrohith (8th September 2015)

  6. #5
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to use for loop to check multiple number of objects

    Hi anda_skoa,

    I have tried the method that was said by you i.e by using the QList but i am unable to store the objects of QCheckBox in to it,I may have done wrong while impletion.
    If it is possible can you please provice me the sample code for storing objects of an QCheckBox into a list.

    Thanks & Regards,
    Rohith.G

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use for loop to check multiple number of objects

    Quote Originally Posted by gunturrohith View Post
    I have tried the method that was said by you i.e by using the QList but i am unable to store the objects of QCheckBox in to it,I may have done wrong while impletion.
    Hard to tell, you forgot to post the code you have.

    Quote Originally Posted by gunturrohith View Post
    If it is possible can you please provice me the sample code for storing objects of an QCheckBox into a list.
    Qt Code:
    1. QList<QCheckBox*> list;
    2. list << checkbox;
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. add multiple QCoombox using loop
    By uz_qt in forum Qt Programming
    Replies: 8
    Last Post: 27th September 2013, 12:24
  2. Replies: 5
    Last Post: 19th February 2013, 16:49
  3. Number of objects in thread?
    By iraytrace in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2011, 23:13
  4. Creating QFile Objects in a loop
    By sky in forum Newbie
    Replies: 1
    Last Post: 3rd December 2010, 09:27
  5. Check if a object is null and destroy objects
    By ruben.rodrigues in forum Newbie
    Replies: 3
    Last Post: 2nd July 2010, 11:25

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.