I am having trouble with an application that uses QLists to store pointers to objects. I create a QList of pointers to objects in a function, and return it. In the destructor of each object (which is in turn a QList of pointers to objects) I have the standard qDeleteAll(); clear(); rigmarole.
Now, whenever I use that function (it's loading an XML file off disk) to provide a QList which I use to populate a QAbstractModelItem implementation, the program crashes with a SIGSEV pointing to the destructor of the object. This would seem to point to the returned QList going out of scope, and deleting it's container. Then when the model comes around to accessing the data that it thinks it can, the data pointed to by it's internal QList has been deleted, since it is after all an array of pointers. This behaviour isn't exhibited BTW if I comment out the qDeleteAll(); clear(); in the destructor.
I am trying to write the classes contained in the QList to have deep copy constructor, so that when a copy does take place then the data is actually copied, and not just the pointers. I may be going about this in the wrong way, but I made a minimal program to demonstrate what I am trying to do. If you run it, you can see that the copy constructors are never called. My question is, what is neccessary to do to get the QList to actually make deep copies of the data it contains when the QList contains pointers? Or am I going about this the wrong way, and should I just store the objects by value?
You can compile the program using CMake >= 2.4
TIA,
Valheru
Bookmarks