summaryrefslogtreecommitdiff
path: root/src/declarative
diff options
context:
space:
mode:
authorFlorian Hänel <florian.haenel@basyskom.com>2012-03-13 09:43:49 +0100
committerQt by Nokia <qt-info@nokia.com>2012-07-25 02:04:43 +0200
commit2bc8b25c3e34d8accc53f89e19f6294ccfec620f (patch)
treee03fd40bc02f88ddf61308abe41cc51adfdf53fd /src/declarative
parent40d8205ef4a8b03b0b66432775b6ba8b62acb91f (diff)
downloadqt4-tools-2bc8b25c3e34d8accc53f89e19f6294ccfec620f.tar.gz
Fix roundtrip between double and string in QDeclarativeListModel leading to precision issues
Change-Id: Ib667dc79072e900f200943f05fb3db9512f4282e Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index b87f9144d2..8af1fd4138 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));