Custom Time
-
Hi
Could you help me please,
I know how to set the time and update it periodically using.tmrUpdTime = new QTimer(this); tmrUpdTime->setInterval(500); connect(tmrUpdTime, SIGNAL(timeout()), this, SLOT(updateDateTime())); tmrUpdTime->start(); lblTime->setText(QTime::currentTime().toString(timeFormatStr));
But if I accept a custom time for example 10:15 pm from user input.
How do I start a clock counting from this point custom time-point?
If I use above it will just call the currenttime and overwrite it to the current time. -
Hi and welcome to devnet,
One way would be to store the delta between the time set by the user and the system time and recalculate the value when updating.
-
That's one way to do it yes.
Out of curiosity, what is your goal with allowing people setting arbitrary time ?
-
@SGaist it's a project I'm working on where there is the option to set time and date within settings.
The tablet it is been used on may not have internet access.So I though whatever they set it to I'll just start my clock from there.
Kinda new to this. Is there a better way do you think? -
That still feels strange. Why would the user not change the system time in that case ?
-
Then question should rather be: why do you need that modified time in the first place ?
-
@nanamo said in Custom Time:
Does not every app come with an option to alter time and date?
I'm not aware of any apps that provide this option. Can you give an example?
Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()
When your user sets a custom time, calculate the difference between the custom time and the system clock (
QTime::currentTime()
). Record this difference (also known as the offset).Then, whenever you need to calculate or display the time, add the offset to the system time:
QTime::currentTime().addSecs(offset)
. -
@JKSH said in Custom Time:
@nanamo said in Custom Time:
Does not every app come with an option to alter time and date?
I'm not aware of any apps that provide this option. Can you give an example?
Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime()
When your user sets a custom time, calculate the difference between the custom time and the system clock (
QTime::currentTime()
). Record this difference (also known as the offset).Then, whenever you need to calculate or display the time, add the offset to the system time:
QTime::currentTime().addSecs(offset)
.The coded version of what I suggested in my first answer ^^
-
@SGaist said in Custom Time:
The coded version of what I suggested in my first answer ^^
Ack, I didn't read the thread carefully; sorry!
-
@JKSH said in Custom Time:
@SGaist said in Custom Time:
The coded version of what I suggested in my first answer ^^
Ack, I didn't read the thread carefully; sorry!
No worries ! I just found it funny :-D
You made my point clearer so @nanamo has understood it better so it's all good :-)