Results 1 to 10 of 10

Thread: Qt layout memory issue

Threaded View

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

    Default Re: Qt layout memory issue

    Thanks marcel,

    Actually mWidget is a pointer on the widget.
    Assigning it to NULL doesn't change a thing.

    another example :

    This works :
    Qt Code:
    1. ZeTextWidget * textWidget = new ZeTextWidget("Salut");
    2. QHBoxLayout * layout = new QHBoxLayout();
    3. layout->addWidget(textWidget);
    4. delete layout;
    5. delete textWidget;
    To copy to clipboard, switch view to plain text mode 

    This one crashes :

    Qt Code:
    1. ZeTextWidget textWidget("Salut");
    2. QHBoxLayout * layout = new QHBoxLayout();
    3. layout->addWidget(&textWidget);
    4. delete layout;
    To copy to clipboard, switch view to plain text mode 

    Thos two pieces of code are all the same for me.

    - In one case :
    - I'm declaring a self allowed variable in local
    - Assigning it to the layout.
    - Deleting the layout
    - the self allowed variable is/should be deleted at the end of the function locally.

    - In another case :
    - I'm declaring a pointer variable
    - Allocating it myself.
    - Assigning it to the layout.
    - Deleting the layout
    - Deleting the pointer manually.

    Imho the result is/should be exactly the same.
    Last edited by bunjee; 23rd August 2007 at 17:12.

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. Qt layout issue
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 15th August 2007, 19:43
  3. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42
  4. Qt4 widget and nested layout issue.
    By bunjee in forum Qt Programming
    Replies: 12
    Last Post: 18th January 2007, 20:29
  5. "dynamic" layout
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2006, 07: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.