Implementation of QT scheduled call slot Functions

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.