In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
timer
First of all, the above picture
The interface construction is mainly lcdnumber and textbrowser.
First, the timing function is implemented, using the QTime class.
QTime class
Basic function
QTime (int h, int m, int s = 0, int ms = 0) / / constructor
QTime addMSecs (int ms) const / / A pair of time changes, of course, there is also the corresponding addSec function int hour () const / / to get the hours of the current time, similarly, minute,second,msecint elapsed () const / / returns the elapsed time from pause to restart int restart () and void start () / / restart and start, note that restart has a return value of elapsed time int msecsTo (const QTime & t) const / / compares the time difference between the two Qtime classes
Static member
QTime currentTime () / / get the current time QTimer class (timer)
Basic function
Void start (int msec) / / how many milliseconds to send a signal void stop () / / stop sending a signal
Signal
Void timeout () / / send this signal when the rest time is over
Use
QTimer * timer = new QTimer (this); connect (timer, SIGNAL (timeout ()), this, SLOT (update (); / / update () is the function you want to call, of course, it is not necessary for this to accept timer- > start (1000).
In fact, repeated updates to the window are maintained by calling the exec () function in Qtimer. But repeated updates bring a huge amount of work, which is expected to be solved in a threaded way (we'll talk about it later).
Timers are divided into precise and rough types, but no matter which kind of timer depends on its operating system and hardware performance. If the system is too busy to guarantee the accuracy of all requests of the timer, then no matter which kind of timer it is, there will be a deviation.
Introduction to the window LCDnumber: it needs to be emphasized that it cannot get the displayed text, and if you do need text, you can connect its display () function to a slot function. Can be used to display Qstringtextbrowser: rich text edit box, read-only but not editable. The textedit class does not have the implementation of the rich text editing function to click the start button, it needs to be able to start timing. So I create a Qtime object in the constructor of Mainwindow to record the current time of the computer at the moment the start key is pressed. When I press pause or stop to create another Qtime object, the two objects compare the difference, the difference is the recording time. Because of my LCD real-time display, I'm going to initialize the LCD at the beginning.
This- > ui- > lcdNumber- > display ("00VlV 0000VOG 00000")
Then write an object of Qtimer in the Mainwindow constructor and let LCD update the time every millisecond. Change the bug on the button: for example, you can't pause when you press stop. Only appendText () (append) is needed to display the dotted data to textbrowser. When stopping, there should be a clear key to clear all dotted records and set the LCD to zero when the pause time should be removed.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.