PDA

View Full Version : Qpainter in Constructor



augusbas
26th October 2010, 12:27
Hi all,

I created a class and places some public variables to use in class functions:

QImage resultImage;

Now i need to declare a QPainter too in the Public and use with all the functions.

QPainter radar_painter(&resultImage); this code how do i declare in constructor and use the variable in all functions for drawing or updating.

Please help me.

Regards,
Augus.

nish
26th October 2010, 12:36
MyClass::MyClass(): radar_painter(&resultImage)
{

}

make sure QImage is placed first in class declaration than qpainter...
i would suggest u to use a pointer instead of the stack variable.

augusbas
26th October 2010, 13:02
MyClass::MyClass(): radar_painter(&resultImage)
{

}




make sure QImage is placed first in class declaration than qpainter...
i would suggest u to use a pointer instead of the stack variable.


Hi,

I did the same way as you have mentioned,

Declared Qimage first and Qpainter after.

Bit Confusing on waht you have asked to me do.

QImage *resultimage;

and how to pass this varaible to a QPainter in constructor ..

If i am wrong please correct me ...If need i will put my code of waht i am trying to do..

Please help me.

nish
27th October 2010, 12:15
your code is working or not? what is the error now?

wysota
28th October 2010, 00:45
Why do you want to have the painter object as a member variable of the class? That's not how we usually use QPainter.