PDA

View Full Version : Error Message "Paint device returned engine == 0, type:1"



yuzhouzhiwai
27th April 2012, 06:47
hello ,
I wrote a class named CEditorWin, and inherits QFrame class. I set the Attribute of CEditorWin with "setAttribute(Qt::WA_PaintOutsidePaintEvent);". And I know what the Qt Assitant say
"Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting."

When I run the code below, it will return the Error Message "Paint device returned engine == 0, type:1" and the variable "ret" == FALSE.


CEditorWin *m_pCanvas = new CEditorWin();
QPainter *m_pPainter= new QPainter();
assert(m_pPainter != NULL);
bool ret = m_pPainter->begin(m_pCanvas);
assert(ret != FALSE);

I think I write the code Strictly in accordance with what Qt says, but I also get the error. Why? I need help . Thanks very much.

Added after 1 47 minutes:

Sorry, My English is not good. I don't know what i say is clear.
But I really want to solve it. I follow the source code to qpainter.cpp and qwidget_win.cpp. And I found the difference between the source code of Qt 4.7 and the source code of Qt 4.3 is huge. For example : the function "QPaintEngine *QWidget::paintEngine() const" in qwidget_win.cpp
Can someone help me and explain to me the reason ?
Thanks

viulskiez
27th April 2012, 08:37
Is your code inside paintEvent?

yuzhouzhiwai
27th April 2012, 09:21
No, But I set the Attribute:
m_pCanvas->setAttribute(Qt::WA_PaintOutsidePaintEvent);

viulskiez
27th April 2012, 09:27
Based on Qt documentation, Qt::WA_PaintOutsidePaintEvent makes it possible to use QPainter to paint on the widget outside paintEvent(). This flag is not supported on Windows, Mac OS X or Embedded Linux.

yuzhouzhiwai
27th April 2012, 10:14
哈哈 是我弄错了。〠。。
Oh,I know. My English is really bad. I have a wrong interpretation about "On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting".

thanks

Added after 15 minutes:

Ok. But If I still user QPainter to paint on the widget outside paintEvent(), and I ignore the error message("Paint device returned engine == 0, type:1"), what is the result?

I do use it like that, And I get right result up to now.

thanks

Spitfire
30th April 2012, 10:33
That message means that the painter wasn't initialized, so you can't use it for paining.

If you try you should get "Painter not active" error and nothing should be drawn.