Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1
My Carrier: Movistar
Accepted Solution

how can i show the current time on an app

Hi, I try with this:

Label {
text: {
var hours = Qt.formatDateTime (new Date (), "hh : mm a);
return hours;
}
}

Got so far the hour and minutes correctly but it isn't automatically update, what is missing or is there another way to do that?
Please use plain text.
Developer
greenmr
Posts: 862
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: how can i show the current time on an app

[ Edited ]

To continuously update the time you would need an interval timer, preferably with a 60 second interval, to redisplay the Label once per minute. You can do this either with a QTimer which triggers a slot each time it times out, or just call QTimer::singleShot(60000), and then call it again after each update of your Label.

 

Something like this should do what you want:

 

Page {
   attachedObjects: [
      QTimer {
         id: timer
         interval: 60000
         onTimeout: {
            label.text = Qt.formatDateTime (new Date (), "hh : mm a);
         }
      }
   ]
   Label {
      id: label
text: Qt.formatDateTime (new Date (), "hh : mm a) } onCreationCompleted: { timer.start(); } }

Note that the accuracy of your clock depends on exactly when you start it. Since it only updates once per minute it could be up to 59 seconds off. To improve that you could reduce the interval so it updates more often. An interval of 1000 would mean the clock could only be up to one second off. 



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1
My Carrier: Movistar

Re: how can i show the current time on an app

woow, tnks man, that work perfectly, just one detail, when the app loads, the time loads after a sec and it seems like it get from right to left or something like that, is there a way to load it fast or at the same time that load everything else?

 

tnks again for the quick response :smileyhappy:

Please use plain text.
Developer
greenmr
Posts: 862
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: how can i show the current time on an app

Well, in my original code I didn't bother to set the initial label.text value, so it won't display until the first QTimer timeout, however long you set that for. I just edited my post to add one line to my code right after id:label. This should solve your problem.

 


edusal100 wrote:

woow, tnks man, that work perfectly, just one detail, when the app loads, the time loads after a sec and it seems like it get from right to left or something like that, is there a way to load it fast or at the same time that load everything else?

 

tnks again for the quick response :smileyhappy:






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1
My Carrier: Movistar

Re: how can i show the current time on an app

Tnks indeed it solve it :smileyhappy:
Please use plain text.