Results 1 to 2 of 2

Thread: QSet Move Insertion of Explicitly Shared Objects (C++11 & QSharedData Paradigm)

  1. #1
    Join Date
    Sep 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSet Move Insertion of Explicitly Shared Objects (C++11 & QSharedData Paradigm)

    Hello World,

    So I am trying to use QExplicitlySharedDataPointer and QSharedData to create classes that can be stored in a QSet using explicit data sharing for memory management. Each class contains a copy and move constructor and operator overloads for move and copy assignment. I have a unit test that verifies my code, and all everything works as I expect it to.

    The issue I am having is that when one of these objects is inserted into QSet, QSet duplicates the object when adding it to the set using the object's copy constructor instead of the move constructor. I want the object's data to be "moved into" the set... not copied in. I have tried using QSet<Object>.insert( std::move( object ) ), but no matter what I do the copy constructor is called instead of the move constructor. I am using Qt 4.8.1 and the newest Qt Creator release for Linux - GCC 4.7 compiler with the -std=c++11 compiler flag set.

    Is this possible with Qt 4.8.1? I really don't want to have to roll out my own collection classes for this project.

    Thank you for your help.
    The MacFreak84

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSet Move Insertion of Explicitly Shared Objects (C++11 & QSharedData Paradigm)

    Quote Originally Posted by MacFreak84 View Post
    The issue I am having is that when one of these objects is inserted into QSet, QSet duplicates the object when adding it to the set using the object's copy constructor instead of the move constructor.
    That's the correct behaviour, if you ask me...

    I want the object's data to be "moved into" the set... not copied in. I have tried using QSet<Object>.insert( std::move( object ) ), but no matter what I do the copy constructor is called instead of the move constructor.
    How are you creating "object"?

    Besides, if you have explicitly shared data, I don't see any serious benefits of "moving" the data. With explicit sharing you are only copying a pointer and bumping up the reference counter (1 or 2 machine instructions).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. 100% correct usage of QSharedData
    By coder2012 in forum Qt Programming
    Replies: 4
    Last Post: 21st May 2012, 01:14
  2. Replies: 3
    Last Post: 16th January 2012, 22:13
  3. problem with QString and QsharedData
    By jrch2k10 in forum Qt Programming
    Replies: 4
    Last Post: 12th July 2011, 14:45
  4. QsharedMemory or QsharedData ?
    By OverTheOCean in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2010, 22:33
  5. QSharedData - implicit sharing
    By gyre in forum Newbie
    Replies: 4
    Last Post: 28th October 2007, 19:09

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.