×
Namespaces

Variants
Actions

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

From Nokia Developer 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
Compatibility
Platform(s): Symbian, Maemo, MeeGo, Desktop
Symbian
Article
Keywords: Qt, QPainter, errors
Created: gnuton (20 Jun 2011)
Last edited: hamishwillee (13 Jun 2012)

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.

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