Details
-
Bug
-
Resolution: Invalid
-
P3: Somewhat important
-
4.7.0, 4.7.4, 4.8.0, 5.5.0
-
None
-
Windows
Description
A short example from Qt Creator (src/plugins/debugger/watchhandler.cpp, line 1431):
QLabel *l; int width, height, format; uchar *bits; // assign reasonable values to the above... QImage im(bits, width, height, QImage::Format(format)); l->setPixmap(QPixmap::fromImage(im));
The ctor of Qimage uses the memory "bits" points to without copying. This is okay, as the docs mention this.
On Windows, neither fromImage() nor setPixmap() copy the data so that the QLabel still uses the same memory and shows random pixels after the memory "bits" points to was deleted. Calling QPixmap::detach() doesn't help as the reference count is 1.
I don't think that this is the intended behavior. If it is then it must be documented.
We worked around this by adding the following lines in between. If you have a better idea, please let me know.
// enforcing copy of image data
QImage im2(im);
im.detach();
Attachments
Issue Links
- duplicates
-
QTBUG-25543 QImage: Assignment operator and copy constructor do not copy data when original image was created from raw pointer
-
- Closed
-