Results 1 to 3 of 3

Thread: access the members of the Form from a loop.

  1. #1
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default access the members of the Form from a loop.

    Hi all,

    I have a form which includes several widgets(lineedits). Is it possible to read all of them programmatically without reading one by one? Perhaps through a loop.

    Can this applied to any widget as well?

    Many thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: access the members of the Form from a loop.

    Assuming all these labels have a common parent widget (The Form containing them) this may be a viable solution:
    Qt Code:
    1. QList<QLabel*> labels = this->findChildren<QLabel *>(); // This refers to the formwidget
    2. foreach(QLabel* lb, labels) {
    3. // do something with the labels
    4. }
    To copy to clipboard, switch view to plain text mode 
    Hope I could help you.

    Kind regards
    momesana

  3. The following user says thank you to momesana for this useful post:

    cbarmpar (25th September 2008)

  4. #3
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: access the members of the Form from a loop.

    Many thanks friend thats what i wanted.

    Regards.

Similar Threads

  1. How can I access public variable parent Form
    By validator in forum Qt Programming
    Replies: 14
    Last Post: 18th December 2008, 21:12
  2. Replies: 4
    Last Post: 26th June 2007, 19:19

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.