Results 1 to 2 of 2

Thread: Parent Widget scope

  1. #1
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Parent Widget scope

    Hi, probably this question was discussed before, but I do not find the answer in the forum archive...
    Short: I need to access the parent Widget scope from a child widget...
    The code I use is the follow, in the child widget :

    Qt Code:
    1. foreach (QWidget *widget, QApplication::topLevelWidgets())
    2. {
    3. this->myMainForm = qobject_cast<MainForm *>(widget);
    4. if(this->myMainForm)
    5. {
    6. break;
    7. }
    8. }
    9.  
    10. this->myMainForm->parentivar;
    To copy to clipboard, switch view to plain text mode 

    The code works, but is it the correct and best approach to access a parent widget ivar, from a child widget ?
    Thank you in advance for the answer.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Parent Widget scope

    just use the parent() method.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    _Jack_ (21st May 2010)

Similar Threads

  1. How to Create child widget behind parent widget?
    By anupamgee in forum Qt Programming
    Replies: 6
    Last Post: 22nd June 2010, 14:03
  2. Replies: 7
    Last Post: 14th January 2010, 09:47
  3. Replies: 4
    Last Post: 3rd October 2009, 09:19
  4. How to move child widget with parent widget?
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 16:23
  5. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 13:00

Tags for this Thread

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.