Results 1 to 10 of 10

Thread: Qt widget setParent

Threaded View

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

    Default Re: Qt widget setParent

    Because you are lucky and the order in which the compiler deletes objects that goes out of scope is exactly the one that is needed to avoid a crash. I don't want to inspect your code right now, so I'll give an easy example:
    Qt Code:
    1. #include <QObject>
    2. int main(int argc, char **argv){
    3. QObject o1;
    4. QObject o2;
    5. o2.setParent(&o1);
    6. return 0;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Run this application and see if it crashes. Then switch lines 3. and 4. and run it again and again see if it crashes.

  2. The following 2 users say thank you to wysota for this useful post:

    bunjee (30th November 2007), dsab123 (6th July 2012)

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.