PDA

View Full Version : QT 4.4.0 Upgrade QPainter Problem



ChrisReath
10th May 2008, 20:25
Hello all,

I recently upgraded from QT 4.3.4 to 4.4.0. When I upgraded, my GUI started giving me an "ASSERT: SharedPainter ? SharedPainter->isActive() : true" error and then the program craps out.

Here is the stack trace:


QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::restore: Painter not active
ASSERT: "sharedPainter ? sharedPainter->isActive() : true" in file kernel\qwidget.cpp, line 4398

Anyone have any idea?

Thanks,

Chris

thomir
11th May 2008, 16:09
...

Note sure what the problem is, but perhaps you have more than one painter trying to paint the same device at once?

Sounds obvious, but are you calling QPainter::begin and QPainter::end correctly? If you're using the constructor instead of begin(), make sure the QPainter object is really being destroyed.

Also, the output you posted isn't a stack trace - if you still can't work it out, posting a backtrace at the point of the assert might help debug the issue (I'm guessing that it'd lead you back to one of the conflicting QPainter objects anyway).

HTH!

ChrisReath
13th May 2008, 14:44
Hey -- Tried your advice above and still got the same result. This is what the call stack looks like at the point of the Assert:

QTCored4.dll!67037ad()
QtCored4.dll!670375a1()

and then nothing else. Strange indeed.

ChrisReath
13th May 2008, 15:24
Actually, you were absolutely right. You can only have one QPainter Object in existence at one time.

If you use this method to create QPainter Objects:


void MyWidget::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.drawLine(...); // drawing code
}

You have to be careful because you can't use another QPainter p(this) object in the same function. So you are almost always better off using this method:


void MyWidget::paintEvent(QPaintEvent *)
{
QPainter p;
p.begin(this);
p.drawLine(...); // drawing code
p.end();
}

to create QPainter objects so you can begin() and end() Painter Objects appropriately. Thanks for your help.

Chris

ChrisReath
13th May 2008, 15:25
Also, for some reason, QT didn't bother with this assert error in 4.3.4, it is something new they added in 4.4.0 to protect the user.