This is the way the program behaves essentially:
class SecondWidget{//The class to whom I pass the painter
public:
SecondWidget(...,QPainter &painter,...) {p=painter;}
private:
void draw();
QPainter p;
};
SecondWidget::draw(){
p.drawSomething.......
}
class MainWidget{//The main class
...
public slot:
void paintEvent(QPaintEvent *event);
private:
SecondWidget *secondWidget;
..
};
MainWidget:
aintEvent(..){
QPainter paint(this);
paint.draw...
//i draw somthing with the painter
//then I pass it to the other widget
secondWidget = new SecondWidget(paint);
secondWidget->draw();
paint.end();
}
That's all. No,I think it's impossible that the painter gets destroyed before the widget tryies to use it because the compiler whould signal it. Moreover,I don't call any .end() on the painter before the end of the program and the output I get is correct (i.e. the widgets draw what they are supposed to draw).