Results 1 to 2 of 2

Thread: What to free or not to free, that is the question

  1. #1
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default What to free or not to free, that is the question

    When creating widgets in Qt, what do I need to free. Once I do the mainWidget.setLayout(layoutName), do I need to free any memory other than the widget itself? What about icon.setIcon(), does it take over the memory management for the icon?

    I'll just include a sample file. Have I forgotten to free anything in the attached module, as long as I free the parent widget in the calling routine?

    - BRC
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What to free or not to free, that is the question

    Everything seems OK with your code.
    Also take a look at: http://www.qtcentre.org/forum/f-qt-p...ion--5956.html

    Generally you don't need to delete widgets, only in special cases when you allocate temporary widgets without a parent on the heap.

    Also you might allocate QObject's on the heap, like a QList, QThread,ect. These are better to explicitly be deleted when finished using.

    About setIcon: you can only pass a reference to this function, so if you have something like this:
    Qt Code:
    1. QIcon *icon = new QIcon(...);
    2. setIcon(*icon);
    3.  
    4. ...
    5. delete icon;
    To copy to clipboard, switch view to plain text mode 
    You must delete the icon, since the for which you set it owns a copy of your icon.

    Regards
    Regards

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

    bruccutler (27th July 2007)

Similar Threads

  1. Legal question about QT free edition
    By probine in forum General Discussion
    Replies: 10
    Last Post: 5th May 2007, 19:26

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.