Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi. i have a timer in qelapsed timer but i want to start this timer with initial time that is not 0. for example this timer start with 10 second . how i can do it?
thanks
Posted
Comments
Stefan_Lang 4-Jun-14 2:42am    
I don't know QT, but why don't you simply store the initial value in a separate variable, and then add that value to the measured time, later?

1 solution

You can use the hasExpired() function to start your processing only after a specified amount of milliseconds has been expired.

Please refer to the QT documentation for more details:
http://qt-project.org/doc/qt-4.8/qelapsedtimer.html#hasExpired[^]

There you will find the following example:
C++
void executeOperationsForTime(int ms)
{
    QElapsedTimer timer;
    timer.start();

    while (!timer.hasExpired(ms))
        slowOperation1();
}
 
Share this answer
 
Comments
Legor 3-Jun-14 10:13am    
sara 74 wrote:
can you explain it more? i read the article but i don't understand
thanks
Legor 3-Jun-14 10:16am    
I think that you want to use the QElapsedTimer to measure how long a particular part of your code takes?

If you want to start the measurement with 10 seconds (for whatever reason) you just have to wait 10 seconds before you execute the code you want to measure. To do this you can use the function hasExpired() as in the above example. In this example the code you want to measure is the function slowOperation1(). But this function is only executed after a given amount of milliseconds has expired.

Ill leave it to you to figure out how many milliseconds 10 seconds are ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900