Hai friends,
I am new to qt4 and i have a problem in using QPainter to draw lines when mouse is moving by reimplementing mouseMoveEvent.
Problem is that the old drawings are erased after paintEvent.
So only the last drawing is retained on screen after paintEvent. Is there any way to save the old drawings in Qt4 ? Please help?

code is as follows :-

void MainWindow:: paintEvent(QPaintEvent* event)
{
QPainter p;
p.begin(this);
p.drawLine(oldX, oldY, X, Y); // where oldX and oldY are older position of mouse before moving it and X and Y are new positions of mouse.
p.end();
}

void MainWindow::mouseMoveEvent(QMouseEvent* e)
{
oldX = X;
oldY = Y;
X=e->x();
Y=e-Y();
repaint(); // To repaint after mouseMoveEvent()
}