Qt Get the amount of up time for current application
Is there a way in qt to get 开发者_StackOverflow社区the up time of the application as well as the up time for the system?
Thanks in advance.
You can use the QElapsedTimer class from Qt 4.7 to get uptime for your app. This class will use monotonic clocks if it can.
Just create an instance, and call start
on it at the start of your program. From then on, you can get the number of milliseconds your program has been running (or more precisely, since the call to start
) by calling
myElapsedTimer.elapsed()
On Windows
you can simply calculate by calling Winapi
function to get process start datetime
.
More information you can find at http://www.codeproject.com/KB/threads/ProcessTime.aspx
On Linux, you can use the times
system call to tell you elapsed processor time. This will not count the time your program has been idle waiting for input, or blocked waiting for input, or the time that it's been preempted by other programs also running on the system. (Therefore, this makes it very good for benchmarks.)
精彩评论