Results 1 to 3 of 3

Thread: QVector::data() and implicit sharing

  1. #1
    Join Date
    Feb 2009
    Posts
    24
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QVector::data() and implicit sharing

    I have a QVector and need to call the data() function to obtain a value I can use as an argument for a function from a 3rd party library. Does calling data() increase the reference count to the QVector, and if so, is there a way to manually dereference when the 3rd party function has finished executing and I'm done with the pointer?

  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: QVector::data() and implicit sharing

    No, it doesn't. Why would it? You're not making a copy of the vector, only accessing data it holds. Note that if QVector holds items that are reference counted themselves, changing them (through data) might result in changes in reference counts of those items.

    Note that calling data() detaches the vector (it's a non-const method), so the reference count might decrease!
    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.


  3. #3
    Join Date
    Feb 2009
    Posts
    24
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QVector::data() and implicit sharing

    Thanks, I was a bit fuzzy about how implicit sharing worked in Qt, but your explanation cleared it up for me.

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.