Hi Alistair and all

If my memory doesn't let me down all the numbers in _javascript_ are always floats (that you can round/floor/ceil using Math). ints are something QML specific. The fact that QML uses Math.round() when assigning to int properties sounds very logical to me - as it is the closest to the source value.

Easy to fix by subtracting 0.5 but more to the point
I would still go for Math.floor() if flooring down is what you want

Interestingly “property int foo=69.6” fails but “property int foo=696/10.0” doesn’t.
This is interesting :)
I'd love to hear from somebody who knows. My guess is that "foo: 69.6" is evaluated by QML parser that knows about types, but "696/10" is a function call that is executed by _javascript_ engine once QML has prepared the object tree.

The following code, for example works perfectly demonstrating that you can assign exactly 79.6 if it happens at run-time (80 is actually assigned):
  1. import QtQuick 1.0
  2.  
  3. Rectangle {
  4.     // That would have failed with "Invalid property assignment: int expected "
  5.     //property int foo: 69.6
  6.  
  7.     property int foo: 696/100
  8.     width: 100
  9.     height: 62
  10.     Text {
  11.         anchors.fill: parent
  12.         text: foo
  13.     }
  14.  
  15.     Component.onCompleted: {
  16.         foo = 79.6
  17.     }
  18. }

Best regards,
Artem.

On Nov 5, 2011, at 6:54 AM, <[email protected]> <[email protected]> wrote:

property int foo=696/10 evaluates to 70, not 69 as I expected.
 
QML appears to do a round rather than a truncate when assigning a real _expression_ to an int. Easy to fix by subtracting 0.5 but more to the point, is this intended behavior? I could not find anything in the documentation that describes how it should behave.
 
Interestingly “property int foo=69.6” fails but “property int foo=696/10.0” doesn’t.
 
-Alistair
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Reply via email to