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.
Article Metadata
Compatibility
Article
Contents |
Overview
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);
Problem
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.
Solution
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.
Conclusion
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.


Sushmars - QWidget::paintEngine: Should no longer be called QPainter::begin: Paint device returned engine == 0, type: 1
Hi,
In my code i use to draw a real time graph outside paintEvent by setting property WA_PaintOutsidePaintEvent to true for qframe. It is plotting properly in my linux desktop as it is having x11. when i ran the same app in my arm based processor for which we have ported qt, i am getting error QWidget::paintEngine: Should no longer be called QPainter::begin: Paint device returned engine == 0, type: 1
As my arm environment is not having x11,Is this is the problem to draw outside paint event.sushmars 10:57, 7 September 2011 (EEST)
Hamishwillee - @sushmars - discussion boards
Unless you have a specific question about this article, then in general its best to ask your question on the discussion boards. You can of course think to the article for reference. The reason for this is that it increases the chance of someone knowing the answer reading your questionhamishwillee 08:19, 8 September 2011 (EEST)