Results 1 to 5 of 5

Thread: Best way to access one element (widget or layout)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Best way to access one element (widget or layout)

    There's a small overhead of a pointer-per-widget, but member variables are the way to do it for the vast majority of cases. If you use Designer and uic then the generated code uses member variables in exactly the fashion you describe.

    The alternative is to not keep those pointers, but uniquely name each widget, and then use QObject::findChild() to walk recursively down the QObject ownership tree looking for a match (or matches) on name and type. A whole tree walk comparing and casting is much slower then direct access via a stored pointer. This approach is useful for dynamically constructed UIs where the structure cannot be known in advance (perhaps using QUiLoader).

  2. #2
    Join Date
    Aug 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Best way to access one element (widget or layout)

    Thanks a lot, ChrisW67, for you additional answer.

Similar Threads

  1. how to access layout within another layout in qt
    By lakeat in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2013, 06:57
  2. Replies: 2
    Last Post: 29th December 2011, 12:27
  3. Access DOM element from AxWidget
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2011, 16:03
  4. how to access ith element of an qstring list?
    By aurora in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2011, 09:37
  5. Replies: 0
    Last Post: 3rd August 2011, 12:07

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
  •  
Qt is a trademark of The Qt Company.