How can I connect a signal to Qtimer slot start()
-
you can use signal and slot . so where you condition become true there you have to emit signal. and in constructor you can call start timer slot .
-
@dziko147 said in How can I connect a signal to Qtimer slot start():
Hello ,
I want to start the QTimer in a specific condition .
So I think about send a signal to start() slot .
But I couldn't do it .
Who can suggest a way ?
thank youCan you show what you have tried? So it is easier for us to explain what going wrong.
-
connect(&m_fetchFrameTimer, & QTimer::timeout, this, &Backend::statuspican); connect(this,SIGNAL(signalgetdataclicked()),this,SLOT(m_fetchFrameTimer.start(2000))); //I thinked about something like this
-
@dziko147 said in How can I connect a signal to Qtimer slot start():
connect(this,SIGNAL(signalgetdataclicked()),this,SLOT(m_fetchFrameTimer.start(2000))); //I thinked about something like this
This do no made sense.
you can connect a "sender" signal to a "receiver" slot (or signal).
SIGNAL() is used to define the signal to connect (function name and parameter types, not variable names)
SLOT() is used to define the slot to connect (function name and parameter types, not variable names)What you are trying to do is not allowed.
You could use a lambda function, like this (I suppose the class name is
Backend
):connect(this, &Backend::signalgetdataclicked,this, [this](){ m_fetchFrameTimer.start(2000); });
Please, take 1 or 2 minutes to learn how
connect()
works. It is very well documented here: https://doc.qt.io/qt-5/signalsandslots.html -
connect(this,SIGNAL(signalgetdataclicked()),this,SLOT(m_fetchFrameTimer.start(2000)));
since you're probably trying to start the timer with different times, I would suggest a custom signal for this:
signals: .... void startFetchFrameTimer(int interval);
and use that in a "regular" connect,
Old syntax:
connect(this, SIGNAL(startFetchFrameTimer(int)), &m_fetchFrameTimer, SLOT(start(int)));
new Syntax
connect( this, &Backend:: startFetchFrameTimer, &m_fetchFrameTimer, qOverload<int>::of(&QTimer::start));
then you just emit the signal wherever you want, and you're fine to go:
emit startFetchFrameTimer(1000);