#include #include int main(int argc, char **argv) { unsigned char *img = new unsigned char[3]; img[0] = 0; img[1] = 0; img[2] = 0; // Create two images QImage *qimg1 = new QImage(img, 1, 1, QImage::Format_RGB888); QImage *qimg2 = new QImage(5, 5, QImage::Format_RGB888); // Copy image 1 -> image 2 *qimg2 = *qimg1; // This could also be a call over a queued connection, copy constructor has same issue. // Destroy image 1 and the data buffer delete qimg1; delete[] img; // This is valid according to documentation, because the QImage is destroyed // now access the data of the "copied" image unsigned char p0 = qimg2->scanLine(0)[0]; // Access to invalid memory, because now the copy is made from the invalid location qDebug() << static_cast(p0); // This line is here to print the contents of the invalid memory location if the program does not terminate // on the previous line. // If you have a compiler that changes the memory contents when calling "delete[] img;" then // this will not return 0, which proves that this location is invalid. // Apparently Visual Studio 2008 SP1 with debug configuration and attached debugger changes the memory on delete // so you will get 238 instead of 0. return 0; }