Results 1 to 5 of 5

Thread: QList, copy problems

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QList, copy problems

    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
    Attached Files Attached Files

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 18:55
  2. QObject and copy Constructors
    By December in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2008, 16:14
  3. QTextEdit - copy and paste problems in X11
    By chezifresh in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2008, 19:21
  4. QVector copy constructor
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2008, 17:52
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43

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
  •  
Qt is a trademark of The Qt Company.