Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » [SOLVED] Showing elapsed time
[SOLVED] Showing elapsed time [message #47588] Thu, 02 February 2017 15:59 Go to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi there,
I have this application that measures the time an operator in a factory spends to perform some activity. The operator pushes a start button, perform his activity and when he is done comes backs, enter a description of the activity performed and the press a stop button to save everything into a database. When the operator pushes the start button a record is saved into the database with the ID and the start time. When he pushes the stop button the record is updated with the end time. I need to show on the window a control with the elapsed time i.e. the time spent by the operator performing the activity. This timer should shows zero when the start button is pushed and should reset when the stop button is pushed. I know that it is an easy task to implement this, but I spent a lot of time lurking the forum and reading the documentation, without find a way to do that. Could someone give me a help on this?
Thanks,
Gio

[Updated on: Fri, 03 February 2017 09:03]

Report message to a moderator

Re: Showing elapsed time [message #47590 is a reply to message #47588] Thu, 02 February 2017 18:37 Go to previous messageGo to next message
deep is currently offline  deep
Messages: 263
Registered: July 2011
Location: Bangalore
Experienced Member
Use GetSysTime() function.

Time start, end;

start = GetSysTime(); // at start
end = GetSysTime(); // When stop button pressed.

(end - start) will be int64 elapsed time.

if you want to show continuous elapsed time from start.
use SetTimeCallback at desired interval to show elpsed time.
Callback function to calculate elapsed time.


Warm Regards

Deepak

[Updated on: Thu, 02 February 2017 18:43]

Report message to a moderator

[SOLVED] Re: Showing elapsed time [message #47591 is a reply to message #47590] Fri, 03 February 2017 09:03 Go to previous message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
deep wrote on Thu, 02 February 2017 18:37
Use GetSysTime() function.
use SetTimeCallback at desired interval to show elpsed time.
Callback function to calculate elapsed time.


Hi Deep,
thank you for your answer. I found in the documentation that I had to use SetTimeCallBack, but my problem was how to use it properly. Probably is a trivial problem, but as a newbie I could not find a way to put together all these bit and pieces. At the end I found this way: I share it here, maybe it could be useful in future for other newbies.

In the constructor of the main object (in my case the window called "HomeScreen" containing the label I put the timer in):
SetTimeCallback(-1000, callback(this , &HomeScreen::Timer));


The function Timer is the one called to show/refresh the
void HomeScreen::Timer()
	{
		int64 sectot = myMLav.GetTimer();
		
		int secondi = sectot%60;
		int64 minuti = sectot/60 - ((int64)sectot/3600)*60;
		int64 ore = sectot/3600;
		
		StatusTimer.SetText(AsString(ore) + ":" + AsString(minuti) + ":" + AsString(secondi));
	}

Previous Topic: [SOLVED] Converting from 'Upp::Value' to 'char'
Next Topic: Connect with an external static library
Goto Forum:
  


Current Time: Thu Mar 28 22:51:23 CET 2024

Total time taken to generate the page: 0.01183 seconds