QT4 memory management

I come from a fairly strong C background and have a pretty solid foundation in C ++. Most recently, I worked with C # and other higher-level languages. The project I'm working on can really benefit from using QT4, but I have some memory management issues that I don't seem to understand. I read the QT4 documentation and it didn't help me. That is why I am here.

1) So, for starters, I understand that the easiest way to use QT4 objects is to declare them locally:

void MyFunc()
{
     QString foo;
     // do stuff to foo

}

It's simple enough, I can take this object and pass it on and know that when it goes out of scope, it will be destroyed. But here is my question.

1) If I create a QList and add objects to it, and then the QList goes out of scope, will it try to free the child objects?

2) If the QT4 procedure returns a pointer to an object, then am I responsible for de-highlighting this object?

3) If I create a subclass of QWidget and add it to QWindow, how can I guarantee that when the QWindow is destroyed, it will take my widget?

Thanks for the help.

+5
source share
3 answers

If I create a QList and add objects to it, and then the QList goes out of scope, will it try to free the child objects?

QList is exactly like std :: list. It will destroy the contained objects when they are destroyed.

If the Qt4 procedure returns a pointer to an object, then am I responsible for de-highlighting this object?

, , . take * (: QTableWidget:: takeItem).

QWidget QWindow, , QWindow , ?

, .

  • (, QWindow), , -.
  • , Qt ( )
  • .

QWidget ( QObject) , , , .

+13

, : , / Qt ( , ).

1) QList , QList , ?

, , std:: list. , std:: list, . Qt

2) QT4 , - ?

rpg, , .

3) QWidget QWindow, , , QWindow , ?

, ctor. , Qt. , QObject:: setParent (QObject * parent).

+2
+1

All Articles