How to deal with the "time" basic type?
-
Hi, I need a counter that starting with a value e.g. "00:10:00" substracts a second every... second. ;)
I thought this would work:
@ Timer {
property time userTimeValue: "00:10:00"
interval: 1000; running: true; repeat: true
onTriggered: {
userTimeValue = userTimeValue - 1000
userTime.text = userTimeValue
}Text { id: userTime@
but it can't even start counting because the "time" basic type is not recognized:
bq. Error loading component: qrc:/OnlineBoard.qml:366 Expected property type
The related documentation is a bit sparse, at least for a newbie like me: http://developer.qt.nokia.com/doc/qt-4.7/qml-time.html
What is MyTimePicker? It seems to be mentioned only in that page.
Also, once I succeed creating that property, will it be possible to make basic operations with it, like substracting 1000 miliseconds? Can I expect that after 60 seconds it will know that the new value returned has a minute less?
And also, is there a way to present the value as "mm:ss" or "ss" or should I just cut the string using Javascript?
By the way, I believe a countdown timer is a pretty frequent feature. Having it as an example would be welcome. I'm happy contributing mine once I get it to work. :)
-
Check this example: http://www.developer.nokia.com/Community/Wiki/Simple_Qt_timer_application_in_QML
Very ugly example. :)
@import QtQuick 1.0
Text {
property int milliseconds: 1000 * 60 * 10 //ten minutes
property string time: getTime()function getTime() { var minutes = Math.floor(milliseconds / 1000 / 60) var seconds = Math.floor((milliseconds-minutes*1000*60) / 1000) return "00:" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds) } width: 400 height: 400 text: time Timer { interval: 1000; running: true; repeat: true; onTriggered: milliseconds -= 1000 }
}@
-
Hi,
The "basic types" listed in the QML documentation are types that are encountered in QML (might be e.g. as a return value from a C++ function, for example), but not all of them can currently be declared as property types within QML (the list of supported types is much smaller, and is currently available at http://doc.qt.nokia.com/latest/qml-extending-types.html#supported-property-types). The documentation for this is not very clear at the moment, which unfortunately doesn't make this very easy to find out (hopefully this will be improved soon).
Regards,
Michael -
Thanks mbrasser, this explanation makes total sense... now that I read it. :)
You know, one problem with QML is that it's so easy to get started that even newbies like me (or your average designer) can get really far even ignoring the basics of e.g. Qt or Javascript (or programming for that matter). Until you hit one of these obvious things that average developers don't even pay attention.
Looking forward to the improvements in the documentation to make it dummy-friendly.
PS: thanks Diph, your simple timer found its place inside http://gitorious.org/miniature/miniature/blobs/master/src/frontend/OnlineBoard.qml - I still have to retouch it to handle the situation of reaching -1 milliseconds. :)
-
Diph hi !
when i use your code, qml show my this
ReferenceError: milliseconds is not defined
do you know why ? or the reason?? -
[quote author="x89xfelipe" date="1404842956"]Diph hi !
when i use your code, qml show my this
ReferenceError: milliseconds is not defined
do you know why ? or the reason??[/quote]Because you didn't define "milliseconds" ;)Anyway, just use JavaScript date/time functions: http://javascript.info/tutorial/datetime-functions Store your date/time object as a "var" type.
-
You are very kind. thank you for your time ! :D