Qt4.5: Implicitly Shared QImage: Methods like .bits () are always copying (documentation fuzzy)

I am writing a Qt application that needs to handle large QImages. QImage uses implicit sharing, which means that the reference is counting the internal data pointer. Whenever refcount is> 1, the object is considered "shared", and any calls even potentially modifying the data will invoke a deep copy of the image data.

In short: I don't want deep copies to happen.

I am making multiple calls like setPixel (), bits (), etc. that can trigger a copy. The documentation sometimes reads as if certain calls would always cause a deep copy (disconnect the call), even if I try my best to keep the refcount at 1. Like here: QImage :: setPixel ()

So, I want to know:

  • Is the doc just formulated a little awkwardly and these calls only reliably copy shared objects (as in refcount> 1)?
  • Can I ask the object what its current refcount is, for debugging reasons, etc.
  • Can I make Qt not imply sharing specific objects / instances (<- well here's my educated guess "no")
+2


source to share


1 answer


  • Activities that might change the shared instance will be detached. setPixel is detached.
  • Try QImage :: isDetached (), which does return d && d->ref == 1;

    . Using the debugger, you can get the actual recalculation.
  • Except for passing by reference / shared pointer.


+1


source







All Articles