QPainter::begin:Paint device returned engine == 0 (Known Issue)
The paint device returns an error if you paint with an uninitialised QPixmap. The size must be set before it can be used.
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 error above is generated by QPainter::Begin where QPainter is defined as follows:
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.