Question

That's probably a trick question, but I'm not sure;

Do I have to call delete after :

  • QImage::copy()
  • QImage::load(QString)
  • QPixmap::fromImage(QImage)

By delete I mean, deleting it when I don't need it any more.

Was it helpful?

Solution

QImage objects are not special in how they are created and destroyed. On the stack or with new/delete or whatever, the rules are the same as for all C++ objects.

QImage is implicitly shared, so copying it is cheap (like a shared pointer) but it performs copy-on-write to preserve value semantics.

Short story, you probably don't ever have to new/delete a QImage, just pass it around as a value and quit worrying.

You don't have to do any special deleting after calling copy/load methods, although you might want to assign my_image=QImage() to release cached data or something.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top