Results 1 to 10 of 10

Thread: How get a pointer to the parent widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How get a pointer to the parent widget

    I think franco's "problem" is that QWidget::parentWidget() returns a pointer to QWidget and he doesn't know how to make it a pointer to QMainWindow. Another one of those C++ problems
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: How get a pointer to the parent widget

    Quote Originally Posted by wysota View Post
    I think franco's "problem" is that QWidget::parentWidget() returns a pointer to QWidget and he doesn't know how to make it a pointer to QMainWindow. Another one of those C++ problems
    Dear Wysota sorry but you're wrong ( I perfectly know what a cast is ). You are used to underestimate me.
    tbscope the problem is that QMainWindow doesn't see directly the QWidget.
    The QWidgets are created in the centralWidget class that's part of the QMainWindow class.
    I use Visual studio.
    Thank you.
    Franco
    Franco Amato

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

    Default Re: How get a pointer to the parent widget

    Quote Originally Posted by franco.amato View Post
    Dear Wysota sorry but you're wrong ( I perfectly know what a cast is ). You are used to underestimate me.
    tbscope the problem is that QMainWindow doesn't see directly the QWidget.
    The QWidgets are created in the centralWidget class that's part of the QMainWindow class.
    I use Visual studio.
    Thank you.
    Franco
    So QWidget::parentWidget() doesn't work for you? I don't really see the problem... If your widget is a child of a central widget of the main window then obviously:
    1. main window is the grand parent of your widget (parentWidget()->parentWidget())
    2. main window is a window of your widget (this->window())

    Choose either of the two approaches.

    I do not underestimate you, it's just sometimes it is hard to see what you actually have a problem with.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    May 2007
    Posts
    106
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60
    Thanked 3 Times in 3 Posts

    Default Re: How get a pointer to the parent widget

    Hi franco,

    It seems your main window knows both the widgets, so you can simply connect some signal from widgets in main window and act upon them in a slot created in Main window.

    If you want to do it otherway round, you should definitely have access to Main window from widgets and for that you either need to pass it or you need to find it walking through parentWidget tree or it should be globally accessible.

    Manoj

Similar Threads

  1. Replies: 7
    Last Post: 14th January 2010, 08:47
  2. Replies: 7
    Last Post: 26th November 2009, 14:29
  3. Replies: 4
    Last Post: 3rd October 2009, 08:19
  4. using the parent-pointer
    By doktorn in forum Newbie
    Replies: 5
    Last Post: 31st August 2007, 18:59
  5. get Parent Pointer
    By raphaelf in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2006, 13:09

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.