Unsolved Custom 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.
-
@SGaist thanks for the very quick reply.
So basically implement as the code above but add or subtract an offset to the currenttime depending on the user input? -
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 ?
-
@SGaist it will be running on a windows based tablet.
I didn't want to mess with the system time but do
You think this would be the way to go? -
Then question should rather be: why do you need that modified time in the first place ?
-
@SGaist Does not every app come with an option to alter time and date?
I have the user set time and date been accepted
Just need to know how to alter the app clock to this new time as right now the app clock is reading currenttime() -
@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 Brilliant, thanks a lot
-
@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 Yes, thanks to all.
I will try now and see how it goes -
@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 :-)