Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

QPainter::begin:Paint device returned engine == 0 (Known Issue)

From Wiki
Jump to: navigation, search

The paint device returns an error if you paint with an uninitialised QPixmap. The size must be set before it can be used.

Article Metadata
Platform(s): Symbian, Maemo, MeeGo, Desktop
Keywords: Qt, QPainter, errors
Created: gnuton (20 Jun 2011)
Last edited: hamishwillee (13 Jun 2012)



I wrote this page to document an issue that a distracted Qt developer can easily face. As the title says this wiki page is about a QPainter error which is not really explicit and even if it's simple it's not documented anywhere.

The error message printed out in the console is:

Runtime error: QPainter::begin: Paint device returned engine == 0, type: 2

The code

The error above is generated by QPainter::Begin where QPainter is defined as follows:

QPixmap pix;
QPainter painter(&pix);


Since I removed not interesting code, a reader should be able to see immediately where the issue is located. In fact, as defined above, QPainter::begin fails because QPainter tries to write on a null pixmap instantiated by QPixmap pix.


The solution is pretty simple and it's about defining a valid size for the QPixmap to paint. For instance defining it as QPixmap pix(100, 100) fix this issue.


I hope this article could help Qt (lazy) developers who have faced this issue and that are maybe googling for a solution instead of digging inside their code.

This page was last modified on 13 June 2012, at 10:56.
365 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.