Solved Emit a signal fixed number of time with QTimer
-
Hi All,
I am working on a project where i draw an ellipse on Graphics View (using scene). I am using QTimer to emit a signal which triggers the SLOT fuction which draws on Graphics View. After drawing for 9 such times, I want to stop and now draw any more. Is there a way to make QTimer not trigger after 9 signals?
I am using signals to draw on Graphics View, because after each draw I want new ellipse to show immediately. Is there any other solution ?
Thanks,
Anurag -
Hi and welcome to devnet,
Yes: count the number of occurrences it fired and stop the timer after that.
-
Hi @Anurag2904
This would help u.
#include "sample1.h"
sample1::sample1(QObject *parent) : QObject(parent)
{
count = 0;
mtimer.setInterval(1000);
connect(&mtimer,SIGNAL(timeout()),this,SLOT(sLotTimer()));
mtimer.start();
}void sample1::sLotTimer()
{count ++; //business logic qDebug()<<Q_FUNC_INFO<<endl; if(count <= 9){ mtimer.start(); }else{ mtimer.stop(); }
}
-
Thanks a lot guys. Issue solved by issuing stop() when counter hits 9