PDA

View Full Version : Painter not active



bainedyal
30th July 2011, 09:16
Hello all!
I am new in QT C++ Programming and I hope to get some help here.
I am trying to make a simple program with QT.

My goal is to save the parameter of objects to a file and then to load these backwards from the file.

The painting and save-function run without problems, but the load (desterilize) shows the following error messages:
QPainter::setBrush: Painter not active
QPainter:: pen: Painter not active
QPainter::setPen: Painter not active
QPainter::drawRects: Painter not active

I have been trying for few days to eliminate these errors but without success.

Here a snippet of my paintevent-funktion:

Here is my whole project-code: bainedyal.de/painter.zip

If you have any idea please contact me.

Thank you!

mvuori
30th July 2011, 18:39
Here a snippet of my paintevent-funktion:

You forgot the snippet.

helloworld
30th July 2011, 19:46
QPainter works on a QPaintDevice, and in the case of QWidget you can't paint from outside a paint event. I really don't see why you need to paint anything in 'deserialize', however.

The way I understand it, you save the file by serializing the objects to a file stream (in 'serialize'). So, deserialize should do the opposite – that is, parse whatever data you read from the file according to the same rules and add objects correspondingly to the 'objects' vector. Then you simply call update() to repaint the widget (or rather, post an event that will be processed when the program returns to the main event loop).

bainedyal
4th August 2011, 10:06
Hey!

I have done it!