I dont konw how to connect timers timeout and mouseevent class. I need to draw a new particle in "waterfield" (qwidget) when mouse button is pressed every 200 ms. When i release the button painter should not draw more. I got this in my constructor:
timertap.setInterval(200);
timertap.start();
connect(&timertap,SIGNAL(timeout()),this,SLOT(taptap()));
setMouseTracking(true);
In my class there are slot taptap() and bool tapenable.
This is code which is not working:
void waterfield::taptap()
{
QMouseEvent *e;
if(tapenable && e->button()==Qt::LeftButton)
{
particle p;
int x=e->pos().x();
int y=e->pos().y();
p.position.y=y;
p.position.x=x;
zbiorczastek.push_back(p);
painter.drawEllipse(x,y,particlesize,particlesize);
}
}
void waterfield::mousePressEvent(QMouseEvent *e)
{
tapenable=true;
}
void waterfield::mouseReleaseEvent(QMouseEvent *e)
{
tapenable=true;
}
After i click program crashs. I think its a good idea to do it this way. Timer is set to 200ms, so every 200ms signal timeout is set and slot taptap recive it and check if tapenable is set by mousepressevent or reset by mousereleaseevent. Any suggestions?