diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-06-09 08:04:50 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-06-11 12:32:22 (GMT) |
commit | 9a16161889c7f6c15c4d5679148a28fe51f95abb (patch) | |
tree | 671eaeb57ebe611350e9e211dfc0c35ff40f0651 | |
parent | 3ff9474b8e3812f629869bc349ffb0a7f70c93a4 (diff) | |
download | Qt-9a16161889c7f6c15c4d5679148a28fe51f95abb.zip Qt-9a16161889c7f6c15c4d5679148a28fe51f95abb.tar.gz Qt-9a16161889c7f6c15c4d5679148a28fe51f95abb.tar.bz2 |
QMetaType: do not crash when registering builtin stream operator
It is not required to register builtin operator, but old code might
do so if a type was not builtin before.
This is the case of QVariant which became builtin only in Qt 4.7
Task-number: QTBUG-11316
Reviewed-by: Gabriel
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qmetatype/tst_qmetatype.cpp | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index ce9ed58..6ebaaa3 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -378,6 +378,8 @@ void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveO void QMetaType::registerStreamOperators(int idx, SaveOperator saveOp, LoadOperator loadOp) { + if (idx < User) + return; //builtin types should not be registered; QVector<QCustomTypeInfo> *ct = customTypes(); if (!ct) return; diff --git a/tests/auto/qmetatype/tst_qmetatype.cpp b/tests/auto/qmetatype/tst_qmetatype.cpp index f4e122f..8558e06 100644 --- a/tests/auto/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/qmetatype/tst_qmetatype.cpp @@ -77,6 +77,7 @@ private slots: void isRegistered_data(); void isRegistered(); void unregisterType(); + void QTBUG11316_registerStreamBuiltin(); }; @@ -318,5 +319,12 @@ void tst_QMetaType::unregisterType() QCOMPARE(QMetaType::isRegistered(typeId), false); } +void tst_QMetaType::QTBUG11316_registerStreamBuiltin() +{ + //should not crash; + qRegisterMetaTypeStreamOperators<QString>("QString"); + qRegisterMetaTypeStreamOperators<QVariant>("QVariant"); +} + QTEST_MAIN(tst_QMetaType) #include "tst_qmetatype.moc" |