diff options
6 files changed, 35 insertions, 8 deletions
diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc index 5d1e18f..670a218 100644 --- a/doc/src/declarative/qtdeclarative.qdoc +++ b/doc/src/declarative/qtdeclarative.qdoc @@ -91,6 +91,10 @@ qmlRegisterType<MinehuntGame>("MinehuntCore", 0, 1, "Game"); \endcode + Note that it's perfectly reasonable for a library to register types to older versions + than the actual version of the library. Indeed, it is normal for the new library to allow + QML written to previous versions to continue to work, even if more advanced versions of + some of its types are available. */ /*! diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 9e6c060..84146b3 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1736,7 +1736,7 @@ public: found = QDeclarativeMetaType::isModule(uri.toUtf8(), vmaj, vmin); if (!found) { if (errorString) { - bool anyversion = QDeclarativeMetaType::isModule(uri.toUtf8(), 0, 0); + bool anyversion = QDeclarativeMetaType::isModule(uri.toUtf8(), -1, -1); if (anyversion) *errorString = QDeclarativeEngine::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin); else diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index 8fee8a7..d9ea8dc 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -99,8 +99,12 @@ struct QDeclarativeMetaTypeData StringConverters stringConverters; struct ModuleInfo { - ModuleInfo(int maj, int min) : vmajor(maj), vminor(min) {} - int vmajor, vminor; + ModuleInfo(int major, int minor) + : vmajor_min(major), vminor_min(minor), vmajor_max(major), vminor_max(minor) {} + ModuleInfo(int major_min, int minor_min, int major_max, int minor_max) + : vmajor_min(major_min), vminor_min(minor_min), vmajor_max(major_max), vminor_max(minor_max) {} + int vmajor_min, vminor_min; + int vmajor_max, vminor_max; }; typedef QHash<QByteArray, ModuleInfo> ModuleInfoHash; ModuleInfoHash modules; @@ -544,9 +548,15 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t if (type.uri) { QByteArray mod(type.uri); QDeclarativeMetaTypeData::ModuleInfoHash::Iterator it = data->modules.find(mod); - if (it == data->modules.end() - || ((*it).vmajor < type.versionMajor || ((*it).vmajor == type.versionMajor && (*it).vminor < type.versionMinor))) { + if (it == data->modules.end()) { + // New module data->modules.insert(mod, QDeclarativeMetaTypeData::ModuleInfo(type.versionMajor,type.versionMinor)); + } else if ((*it).vmajor_max < type.versionMajor || ((*it).vmajor_max == type.versionMajor && (*it).vminor_max < type.versionMinor)) { + // Newer module + data->modules.insert(mod, QDeclarativeMetaTypeData::ModuleInfo((*it).vmajor_min, (*it).vminor_min, type.versionMajor, type.versionMinor)); + } else if ((*it).vmajor_min > type.versionMajor || ((*it).vmajor_min == type.versionMajor && (*it).vminor_min > type.versionMinor)) { + // Older module + data->modules.insert(mod, QDeclarativeMetaTypeData::ModuleInfo(type.versionMajor, type.versionMinor, (*it).vmajor_min, (*it).vminor_min)); } } @@ -554,15 +564,23 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t } /* - Have any types been registered for \a module with at least versionMajor.versionMinor. + Have any types been registered for \a module with at least versionMajor.versionMinor, and types + for \a module with at most versionMajor.versionMinor. + + So if only 4.7 and 4.9 have been registered, 4.7,4.8, and 4.9 are valid, but not 4.6 nor 4.10. + + Passing -1 for both \a versionMajor \a versionMinor will return true if any version is installed. */ bool QDeclarativeMetaType::isModule(const QByteArray &module, int versionMajor, int versionMinor) { QDeclarativeMetaTypeData *data = metaTypeData(); QDeclarativeMetaTypeData::ModuleInfoHash::Iterator it = data->modules.find(module); return it != data->modules.end() - && ((*it).vmajor > versionMajor || - ((*it).vmajor == versionMajor && (*it).vminor >= versionMinor)); + && ((versionMajor<0 && versionMinor<0) || + (((*it).vmajor_max > versionMajor || + ((*it).vmajor_max == versionMajor && (*it).vminor_max >= versionMinor)) + && ((*it).vmajor_min < versionMajor || + ((*it).vmajor_min == versionMajor && (*it).vminor_min <= versionMinor)))); } QObject *QDeclarativeMetaType::toQObject(const QVariant &v, bool *ok) diff --git a/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.errors.txt new file mode 100644 index 0000000..dfa7a36 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.errors.txt @@ -0,0 +1 @@ +1:1:module "Test" version 0.1 is not installed diff --git a/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.qml b/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.qml new file mode 100644 index 0000000..18514b1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.qml @@ -0,0 +1,3 @@ +import Test 0.1 + +MyTypeObject { } diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index c1397de..c39e6f7 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -277,6 +277,7 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("importVersionMissing (builtin)") << "importVersionMissingBuiltIn.qml" << "importVersionMissingBuiltIn.errors.txt" << false; QTest::newRow("importVersionMissing (installed)") << "importVersionMissingInstalled.qml" << "importVersionMissingInstalled.errors.txt" << false; QTest::newRow("importNonExist (installed)") << "importNonExist.qml" << "importNonExist.errors.txt" << false; + QTest::newRow("importNonExistOlder (installed)") << "importNonExistOlder.qml" << "importNonExistOlder.errors.txt" << false; QTest::newRow("importNewerVersion (installed)") << "importNewerVersion.qml" << "importNewerVersion.errors.txt" << false; QTest::newRow("invalidImportID") << "invalidImportID.qml" << "invalidImportID.errors.txt" << false; |