Recently, a function needs to be called regularly to complete some functions, so I learned how to use the qtimer timer.
BelowCodeI wrote it in my memory. I didn't paste the code that has succeeded. I may make some mistakes, but it is basically not wrong. I can search for something like this on the Internet.
First define a timer
1Qtimer *Timer;2Qobject: connect (timer, signal (timeout ()),This, Slot (repeated bytes ()));/*The first parameter is the signal sender, the second parameter is the signal sent, the third parameter is the signal receiver, and the fourth parameter is the called function.*/3 /*Start the timer. If you don't want to start it at this time, write the following sentence as needed.*/4Timer-> Start (1000);//The unit of time is ms.
Then define a writable aggregate () function. The declaration of this function should be written below the private slot of the header file:
1 VoidLinearregression ()2 {3 ......4}
In this way, every 1 s after timer-> Start (1000) will call commit (). After you know timer-> stop.
However, you should note that if there are other slot functions responding to other signals (such as the Response Function clicked) at this time, it is useless to start the timer at this time.