【发布时间】:2014-12-31 10:05:40
【问题描述】:
我们都知道这个警告来自
bool QPainter::begin(QPaintDevice * device)
警告:绘画设备一次只能由一名画家绘画。
http://doc.qt.io/qt-5/qpainter.html#begin
但是如果我有两个对象共享一个像素图,而一个对象 Bar 包含另一个对象 Foo。
class Foo
{
public:
QPixmap* barPixmap;
void draw()
{
QPainter painter(barPixmap);
painter.drawText(0,0,"FooText");
}
}
class Bar
{
public:
QPixmap* barPixmap;
Foo* fooObject;
}
我得到了类似的东西
Bar::paintEvent(QPaintEvent* )
{
QPainter painter(barPixmap);
painter.drawText(50,50,"BarText");
fooObject->draw();
}
是多图吗?编译器什么也没抛出,而且代码似乎工作正常。
【问题讨论】:
-
它工作但它看起来像 fooObject->draw();对 barPixmap 什么都不做