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
New Developer
como28
Posts: 45
Registered: ‎04-11-2014
My Device: Z10

clock timer

[ Edited ]

i've a question about timer. how to create timer like clock. 

 

example: 

1 minutes =  60 second --> 01:00 --> 00:59 ... until 00:00

 

i can create just second -=  -1 but i dont like clock. please help me used QML

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: clock timer

Which bit are you wanting help with the timer part or UI part?

 

A good starting point for understanding QTimer and linking it to UI elements would be this tutorial...

 

http://developer.blackberry.com/native/documentation/cascades/dev/signals_slots/signals_slots_set_up...


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
New Developer
como28
Posts: 45
Registered: ‎04-11-2014
My Device: Z10

Re: clock timer

i want to timer clock -1 not +1. 

can you give me a simple qml about my problem? i can't use QtTimer

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: clock timer

Did you even bother to read through the link I gave you?

 

That example is a countdown timer using QTimer, the code doesn't get any simpler than what is implemented there, so re-writing something that has already been written and explained in a simple and concise matter is a waste of time frankly.

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
New Developer
como28
Posts: 45
Registered: ‎04-11-2014
My Device: Z10

Re: clock timer

I've read your link, and there was just giving second time. when I want to make like the minute I do not know how. Can you help me?

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: clock timer

Usually you would use the divide and modulo operators to turn seconds in to minutes and seconds.

i.e.

mins = total_seconds / 60
secs = total_seconds % 60

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
New Developer
como28
Posts: 45
Registered: ‎04-11-2014
My Device: Z10

Re: clock timer

oke thanks, i'll try :smileyhappy:

Please use plain text.
New Developer
como28
Posts: 45
Registered: ‎04-11-2014
My Device: Z10

Re: clock timer

where's wrong? the clock not -1 . please correct this: main.qml

import bb.cascades 1.0
import CustomTimer 1.0

Page {
    Container {
        id: root
        property int currentCount: 0
        property int minutes: 0
        
        function hitung(total_second){
            total_second = parseInt(total_second,10);
            var mnt = total_second / 60;
            var scn = total_second % 60;
            
            timer.start();
            
            menit.text = "" + mnt;
            detik.text = "" + scn;
        }
        
        Timer {
            id: timer
            
            // Specify a timeout interval of 1 second
            interval: 1000
            onTimeout: {
                // Decrement the counter and update the countdown text
                root.currentCount -= 1;
                detik.text = "" + root.currentCount;
            } // end of onTimeout signal handler
        } // end of Timer 
        attachedObjects: [
            Timer {
                id: pauseTimer
                
                // Specify a timeout interval of 2 seconds 
                interval: 2000
                
                // When the timeout interval elapses, change the traffic
                // light state, enable the "Change!" button, and stop
                // the pause timer
                onTimeout: {
                    start.enabled = true;
                    pauseTimer.stop();
                }
            }
        ]
        
        Container {
            layout: AbsoluteLayout {
            }
            Label {
                id: menit
                text: "00"
                textStyle.fontWeight: FontWeight.W900
                textStyle.fontSize: FontSize.XXLarge
                layoutProperties: AbsoluteLayoutProperties {
                    positionX: 200
                    positionY: 200
                }
            }
            Label {
                layoutProperties: AbsoluteLayoutProperties {
                    positionX: 400
                    positionY: 200
                }
                text: ":"
                textStyle.fontWeight: FontWeight.W900
                textStyle.fontSize: FontSize.XXLarge
            }
            Label {
                id: detik
                text: "00"
                textStyle.fontWeight: FontWeight.W900
                textStyle.fontSize: FontSize.XXLarge
                layoutProperties: AbsoluteLayoutProperties {
                    positionX: 520
                    positionY: 200
                }
            }
        }
        Container {
            layout: AbsoluteLayout {
            }
            Button {
                id: start
                text: "Start!"
                layoutProperties: AbsoluteLayoutProperties {
                    positionX: 220
                    positionY: 50
                }
                onClicked: {
                    // Set the initial countdown time
                    root.hitung(120);
            }
        }
    }
}
}

 

 

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: clock timer

Can you be a little bit clearer in what your problem is, no one wants to look through a whole load of code looking for non-specific errors.

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: clock timer

Quickly scanning through though I don't know why you have 2 timers and you don't seem to have any stopping code.

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.