diff options
author | Teemu Holappa <teemu.holappa@qt.io> | 2019-10-11 14:30:00 +0300 |
---|---|---|
committer | Teemu Holappa <teemu.holappa@qt.io> | 2019-10-11 17:26:43 +0300 |
commit | 76da530aca3876cc083988b883658673168821a4 (patch) | |
tree | ca00d6c689f8172bdb8bce304c2985af35f9463f | |
parent | 45f95e74297ab3778965319c175a6d726f9c8afe (diff) |
Fix float value binding to an integer
Also NaN values are casted to an integer which causes illegal
integer values.
Task-number: QTBUG-72442
Change-Id: I3ff3c8e4dc493600360448ea30d949c0017da8c3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/qml/qqmlbinding.cpp | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlbinding/data/nanPropertyToInt.qml | 14 | ||||
-rw-r--r-- | tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp | 11 |
3 files changed, 28 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 3a437eab8d..52572be2b2 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -298,8 +298,9 @@ protected: case QMetaType::Int: if (result.isInteger()) return doStore<int>(result.integerValue(), pd, flags); - else if (result.isNumber()) - return doStore<int>(result.doubleValue(), pd, flags); + else if (result.isNumber()) { + return doStore<int>(QV4::StaticValue::toInteger(result.doubleValue()), pd, flags); + } break; case QMetaType::Double: if (result.isNumber()) diff --git a/tests/auto/qml/qqmlbinding/data/nanPropertyToInt.qml b/tests/auto/qml/qqmlbinding/data/nanPropertyToInt.qml new file mode 100644 index 0000000000..366dbf0464 --- /dev/null +++ b/tests/auto/qml/qqmlbinding/data/nanPropertyToInt.qml @@ -0,0 +1,14 @@ +import QtQuick 2.11 + +Item { + visible: true + width: 320 + height: 200 + property int val: other.val + + Rectangle { + id: other + anchors.fill: parent; + property int val: undefined / 2 + } +} diff --git a/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp b/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp index 2c2d311ff7..2610402455 100644 --- a/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp +++ b/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp @@ -56,6 +56,7 @@ private slots: void bindingOverwriting(); void bindToQmlComponent(); void bindingDoesNoWeirdConversion(); + void bindNaNToInt(); private: QQmlEngine engine; @@ -398,6 +399,16 @@ void tst_qqmlbinding::bindingDoesNoWeirdConversion() QVERIFY(colorLabel); } +//QTBUG-72442 +void tst_qqmlbinding::bindNaNToInt() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("nanPropertyToInt.qml")); + QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create())); + + QVERIFY(item != nullptr); + QCOMPARE(item->property("val").toInt(), 0); +} QTEST_MAIN(tst_qqmlbinding) #include "tst_qqmlbinding.moc" |