Home > Mobile >  QTimer how to count
QTimer how to count

Time:09-19

I want to put the timer in the serial data stream, and every time new data, the timer will restart, there is no data for a long time to come over, timer timing slot function called end,
 
F1timer=new QTimer;
F1timer - & gt; stop();
The connect (F1timer, SIGNAL (timeout ()), and this, SLOT (F1timeout ()));
F1timer - & gt; Start (5 * 1000);

Void QWidget: : F1timeout ()
{
F1 - & gt; SetValue (0);
//F1timer - & gt; stop();
//delete F1timer;
}


Now is when the new data, the timer will not reset and count again, how should change? Seek help from a great god,

CodePudding user response:

Calls to start again

CodePudding user response:

Can say about it? I've tried, can't, such as I now set the start value to 5 seconds, if 1 second after the new data, I hope I can start timing QTimer, namely to 5 seconds countdown,

CodePudding user response:

With a global Int variables, divided exactly by 5 (cycle), the remainder is zero, run the processing function, if a new data is detected, the global Int=0

CodePudding user response:

A little leakage, in the operation of the timer, remember to set the global Int++, keep growing

CodePudding user response:

refer to the second floor qq_23858157 response:
can say about it? I've tried, can't, such as I now set the start value to 5 seconds, if 1 second after the new data, I hope I can start timing QTimer, namely to 5 seconds countdown,

The timer is not 5 seconds it again? You 1 second to no timer trigger,,,,
You need a new function to deal with the issue of the timer?


In a train of thought: if define trigger a timer to 1 seconds, if in timing processing function set a global counter Int cout,
Cout to 5, judge whether the data reception,
 
Int count=0;

Void QWidget: : F1timeout ()
{
count++;
If (count==4)
//handle something
F1 - & gt; SetValue (0);
}

CodePudding user response:

It is ok to stop first, start again! By the way, what is your demand? Feel like you handle very unreasonable!

CodePudding user response:

refer to 6th floor feiyangqingyun response:
stop first, it is ok to start again! By the way, what is your demand? Feel like you handle very unreasonable!


Yes it is ok to stop off first and then start my general is also to do so

CodePudding user response:



refer to 6th floor feiyangqingyun response:
stop first, it is ok to start again! By the way, what is your demand? Feel like you handle very unreasonable!



Solve a problem, I thank you, don't shut down, the timer is always appear problem,

CodePudding user response:

The assistant:
Void QTimer: : start (STD: : chrono: : milliseconds msec)
This is an overloaded function.
Starts the or restarts the timer with a timeout of duration msec milliseconds.
If the timer is already running, it will be stopped and restarted.
If singleShot is true, the timer will be activated only once.

Call to start, "If the timer is already running, it will be stopped and restarted." this sentence see?
If you have any questions, may be you have a problem elsewhere

CodePudding user response:

Add in the data over time, the new start
  •  Tags:  
  • Qt
  • Related