Am I responsible for calling delete on the pointer provided by the QImage :: bits () function?

The Qt class QImage

has two versions of its function bits()

, which returns a pointer to the underlying image data. One is const, the other is not. Here is the documentation for the non-envelope version:

Returns a pointer to the first pixel data. This is equivalent to Scanline (0).

Note that QImage uses implicit communication. This function performs a deep copy of the shared pixel data, thereby ensuring that this QImage is the only one using the current return value.

Return type uchar*

.

Does this mean that I am responsible for calling delete

this pointer when I am done with it to avoid a memory leak?

+3


source to share


1 answer


No, it just means that the non-const version causes the QImage to detach from any other instances that share the same data, since you can change it. He still retains ownership. To be sure, the implementation (from Qt 4.7.2):



uchar *QImage::bits()
{
    if (!d)
        return 0;
    detach();
    // In case detach ran out of memory...
    if (!d)
        return 0;
    return d->data;
}

      

+5


source







All Articles