Results 1 to 10 of 10

Thread: Qt layout memory issue

Threaded View

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

    Question Qt layout memory issue

    Hello,

    I have an issue with Qt layout.

    That piece of code is working :
    Qt Code:
    1. ZeTextWidget * textWidget = new ZeTextWidget ("Salut"); // Creating a new Widget
    2. ZeTopListWidget * topListWidget1 = new ZeTopListWidget(*textWidget); // Adding the widget to the layout
    3. topListWidget1->Clear(); // Clearing the object / layout
    4. delete topListWidget1; // Deleting the object containing the layout
    To copy to clipboard, switch view to plain text mode 

    That one isn't :

    Qt Code:
    1. ZeTextWidget textWidget("Salut"); // Creating a local variable
    2. ZeTopListWidget * topListWidget1 = new ZeTopListWidget(textWidget); // Adding the widget to the layout
    3. topListWidget1->Clear(); // Clearing the object / layout
    4. delete topListWidget1; // Deleting the object containing the layout
    To copy to clipboard, switch view to plain text mode 

    When creating my "ZeTopListWidget " I'm doing this :

    Qt Code:
    1. mLayout.addWidget(&widget);
    2. mWidget = &widget;
    To copy to clipboard, switch view to plain text mode 

    When clearing my "ZeTopListWidget" I'm doing this :

    Qt Code:
    1. if (mWidget)
    2. {
    3. mLayout.removeWidget(mWidget);
    4. mWidget = NULL;
    5. }
    To copy to clipboard, switch view to plain text mode 

    When I'm:
    - Adding an allocated variable to the layout.
    - Clearing the layout (removeWidget).
    - Deleting the object containing the layout.
    -> It Works.

    BUT if I'm:

    - Adding a local variable to the layout.
    - Clearing the layout (removeWidget).
    - Deleting the object containing the layout.
    -> Crash on the delete line.

    Obviously something is going wrong when the Layout default dtor is called.
    Provided the fact that I remove the assigned widget before deleting my object and thus its member's layout: it should work fine.

    Is there something I'm missing ?
    Last edited by bunjee; 23rd August 2007 at 13:49.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.