Results 1 to 7 of 7

Thread: Does a parent widget receive a method call or signal when its widgets are created or

  1. #1
    Join Date
    May 2008
    Posts
    9
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Does a parent widget receive a method call or signal when its widgets are created or

    Hello,

    Is there a virtual method or a signal that a widget receives when a new widget is created or displayed that uses the first as its parent?

    For example, I have widget foo, then create a new QWidget bar(foo), so foo is bar's parent. I want foo to do something to bar when bar is created or shown.

    Actually, I'm specifically interested in QDialogs as children of a parent widget.

    Does this make sense? Does anyone have any ideas?

    Thanks

    Reed

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Does a parent widget receive a method call or signal when its widgets are created

    Any QObject receives an event of type QEvent::ChildAdded when a child gets added.
    J-P Nurmi

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

    reed (5th September 2008)

  4. #3
    Join Date
    May 2008
    Posts
    9
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Does a parent widget receive a method call or signal when its widgets are created

    Aha, this may be what I need.... will try it.

    (I'm doing something slightly weird )

    Thanks!

  5. #4
    Join Date
    May 2008
    Posts
    9
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Does a parent widget receive a method call or signal when its widgets are created

    In the QObject docs it says

    "In both cases you can only rely on the child being a QObject (or, if QObject::isWidgetType() returns true, a QWidget). This is because in the QEvent::ChildAdded case the child is not yet fully constructed; in the QEvent::ChildRemoved case it might have already been destructed."

    I'm guessing this is because childAdded() is called by the child's constructor? If so, can I save a pointer to the child, and emit a signal, and then safely access the child widget in the slot for the signal (i.e. when does Qt's next process pending signals)?

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Does a parent widget receive a method call or signal when its widgets are created

    At least if you make the connection explicitly queued, then the object has been fully constructed once the slot fires.
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    reed (5th September 2008)

  8. #6
    Join Date
    May 2008
    Posts
    9
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Does a parent widget receive a method call or signal when its widgets are created

    And, should I use installEventFilter() instead of overriding the childEvent() method in my class?

  9. #7
    Join Date
    May 2008
    Posts
    9
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Does a parent widget receive a method call or signal when its widgets are created

    Quote Originally Posted by jpn View Post
    At least if you make the connection explicitly queued, then the object has been fully constructed once the slot fires.
    ::going off to read about queued connections::

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.