summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Hänel <florian.haenel@basyskom.com>2012-03-13 08:43:49 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-07-25 00:04:43 (GMT)
commit2bc8b25c3e34d8accc53f89e19f6294ccfec620f (patch)
treee03fd40bc02f88ddf61308abe41cc51adfdf53fd
parent40d8205ef4a8b03b0b66432775b6ba8b62acb91f (diff)
downloadQt-2bc8b25c3e34d8accc53f89e19f6294ccfec620f.zip
Qt-2bc8b25c3e34d8accc53f89e19f6294ccfec620f.tar.gz
Qt-2bc8b25c3e34d8accc53f89e19f6294ccfec620f.tar.bz2
Fix roundtrip between double and string in QDeclarativeListModel leading to precision issues
Change-Id: Ib667dc79072e900f200943f05fb3db9512f4282e Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp11
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp4
2 files changed, 11 insertions, 4 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index b87f914..8af1fd4 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -707,7 +707,8 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser
if (variant.isString()) {
d += variant.asString().toUtf8();
} else if (variant.isNumber()) {
- d += QByteArray::number(variant.asNumber(),'g',20);
+ double temp = variant.asNumber();
+ d += QByteArray( reinterpret_cast<const char*>(&temp), sizeof(double));
} else if (variant.isBoolean()) {
d += char(variant.asBoolean());
} else if (variant.isScript()) {
@@ -726,7 +727,8 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser
}
} else {
d[0] = char(QDeclarativeParser::Variant::Number);
- d += QByteArray::number(v);
+ double temp = v;
+ d += QByteArray( reinterpret_cast<const char*>(&temp), sizeof(double));
}
}
}
@@ -782,7 +784,6 @@ QByteArray QDeclarativeListModelParser::compile(const QList<QDeclarativeCustomPa
void QDeclarativeListModelParser::setCustomData(QObject *obj, const QByteArray &d)
{
QDeclarativeListModel *rv = static_cast<QDeclarativeListModel *>(obj);
-
ModelNode *root = new ModelNode(rv->m_nested);
rv->m_nested->m_ownsRoot = true;
rv->m_nested->_root = root;
@@ -824,7 +825,9 @@ void QDeclarativeListModelParser::setCustomData(QObject *obj, const QByteArray &
n->values.append(bool(data[1 + instr.dataIdx]));
break;
case QDeclarativeParser::Variant::Number:
- n->values.append(QByteArray(data + 1 + instr.dataIdx).toDouble());
+ double temp;
+ ::memcpy(&temp, data + 1 + instr.dataIdx, sizeof(double));
+ n->values.append(temp);
break;
case QDeclarativeParser::Variant::String:
n->values.append(QString::fromUtf8(data + 1 + instr.dataIdx));
diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
index 3c41002..b6f80e8 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
@@ -559,6 +559,10 @@ void tst_qdeclarativelistmodel::static_types_data()
QTest::newRow("enum")
<< "ListElement { foo: Text.AlignHCenter }"
<< QVariant(double(QDeclarativeText::AlignHCenter));
+
+ QTest::newRow("real11")
+ << "ListElement { foo: 11 }"
+ << QVariant(11.0);
}
void tst_qdeclarativelistmodel::static_types()