[Qt-interest] Question regarding pointer parameters in functions

Patric userqt at gmail.com
Fri Jul 3 11:24:53 CEST 2009


Is there a way to see which QT functions, that take pointers as parameters, are deleting the memory after that. Because otherwise this code for example, 

 QStandardItemModel model;
 QStandardItem *parentItem = model.invisibleRootItem();
 for (int i = 0; i < 4; ++i) {
     QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
     parentItem->appendRow(item);
     parentItem = item;
 }from my point of view would create memory leak. And we should know when we need to release memory and when not. If the class was imlicitly shared, there would not be a problem. But QStandardItem is not such a class.Regards,Patric----- Original Message ----- 
  From: Donal O'Connor 
  To: Patric 
  Cc: qt-interest at trolltech.com 
  Sent: Friday, July 03, 2009 11:50 AM
  Subject: Re: [Qt-interest] Question regarding pointer parameters in functions


  I think the QStandardItemModel object takes ownership of the memory allocated in this case.


  On Fri, Jul 3, 2009 at 9:49 AM, Donal O'Connor <donaloconnor at gmail.com> wrote:

    No,

    Only objects created on the stack in that function will be removed when function ends.




    2009/7/3 Patric <userqt at gmail.com>

      Hello, 
      does anyone know what happens if we pass a pointer as parameter to function in QT ? 
      Will the function release the memory of the object in the pointer, when it finish working with it ? 

      For example 

      void QStandardItemModel::appendRow ( QStandardItem * item ), if I call it the following way : appendRow(new QStandardItem("testItem"));

      Thank you in advance,
      Patric


      _______________________________________________
      Qt-interest mailing list
      Qt-interest at trolltech.com
      http://lists.trolltech.com/mailman/listinfo/qt-interest





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090703/70ff7118/attachment.html 


More information about the Qt-interest-old mailing list