Results 1 to 5 of 5

Thread: QList, copy problems

Hybrid 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 Re: QList, copy problems

    Hmm, the reason for the crash turns out to be rather different. I was implementing QVariant operators for my classes as per the wiki, so that I could get rid of the QVariant::fromValue( *myObject ) calls. I also put a qDebug() statement in the copy constructor of my class. Then, when calling setData( QModelIndex idx, *myObject ), the debug messages showed that the copy constructor was being called recusively, despite being defined as MyClass::MyClass( const MyClass &other ). This was obviously calling the program to crash. It wasn't even entering the setData() function, as I had qDebug() statements in there to check. It just spins in a loop, making copies of *myObject.

    I am implementing copy constructors as I need the parents to changed when that object it copied, otherwise the QAbstractItemModels can't keep track of tree heirarchy. I am a bit lost as to why this is happening though

  2. #2
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QList, copy problems

    Hi Valheru.

    I've looked at your post and your example code as I'm experiencing the same problems as you did. I your post it seems like you've solved the copy problem? I'm fighting to get my copy function to work and I've ended up doing a deep copy by implementing a clone function, like this. I'm using a QMap instead of your QList.
    Item Item::clone()
    {
    Item itm;
    QMap<int,QVariant>::const_iterator i = this->constBegin();
    while (i != this->constEnd()) {
    itm[i.key()] = i.value();
    ++i;
    }
    return itm;
    }

    If it's not too much trouble, will you share with me your solution from above?

    Thanks

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.