Results 1 to 10 of 10

Thread: Qt widget setParent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt widget setParent

    QObjects store children as a list containing QObject pointers. When you delete the object or QObject destructor is called, it calls delete on all its children.

    Now you can see the scenario in your case where you allocate QObjects on a stack and it does have parent. When parent is destructed , delete is called on object on stack which crashes your program.

    edit: I was bit late(jpn answered first) but atleast better late than never
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  2. #2
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Qt widget setParent

    I don't have any crash with my application .

    My problem is memory.

    According to Qt Doc :
    Warning: It is very unlikely that you will ever need this function. If you have a widget that changes its content dynamically, it is far easier to use QStackedWidget.
    Does setting parent to compromise anything for deletion I'm not aware off ?

  3. #3
    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: Qt widget setParent

    Quote Originally Posted by bunjee View Post
    It seems to prevent the widget from deletion, even when I'm calling delete widget, I'm not sure why.
    What does this mean, actually? What do you mean with "prevent something from deletion"?

    Quote Originally Posted by bunjee View Post
    You're not the first to tell me so.
    Indeed, seems you've been warned before in this thread by a bunch of people. Why do you insist doing it wrong? Have you seen any Qt examples allocating widgets or layouts on the stack (excluding main() and modal dialogs)? Or did you ever actually read any of them? Sorry for the tone, but I just don't understand people who regardless of continuous warnings insist of doing things their own (wrong) way.

    Quote Originally Posted by bunjee View Post
    My problem is memory.
    What exact steps did you take to verify this?
    J-P Nurmi

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

    bunjee (30th November 2007)

Similar Threads

  1. Drawing a widget in QItemDelegate's paint method
    By darkadept in forum Qt Programming
    Replies: 17
    Last Post: 11th August 2009, 05:15
  2. Replies: 3
    Last Post: 17th October 2007, 12:52
  3. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  4. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 14:27
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.