Question

In this code:

QPainter painter(&image);

// do painting .......

painter.end(); // is this needed?
image.save(tempFileName);

do I need to close the QPainter before saving the QImage, in order to flush all changes, or can I save it before closing the QPainter object?

Was it helpful?

Solution

Yes, you should call painter.end() prior to calling image.save(). The behavior of painter.end() ultimately depends on the underlying paint engine used on whatever platform your program is running on. You may be able to get away with calling image.save() before painter.end() on some platforms with some versions of Qt, but changing either your platform or your version of Qt could cause you problems later on.

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