diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-02-02 09:32:17 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-02-02 09:50:13 +0000 |
commit | 61a32b78db418936ca7987ff859f9e62f84cbd06 (patch) | |
tree | ffc64e668b1fb52c777c702411cfcb6f88582eb7 /tests/auto/qml/qqmlmoduleplugin | |
parent | b82296f825daf0ba110fea4aa1b61f96d63f371b (diff) |
Lift restriction for type registrations in QML module plugins
During the registerTypes() callback in a QML module plugin we only allow
types to be registered that match the module URI specified in the
qmldir.
We can observe in QtQuickControls 2 that sometimes we need to register
types outside of the namespace of the module itself. QQC2 is in
QtQuick.Controls but the module has internal types that are in
QtQuick.Controls.impl.
Types are intended to be registered once in the virtual registerTypes()
function. However as we don't allow for the registration of .impl to
happen in registerTypes(), QQC2 works around this by registering the
types in initializeEngine(), during which the namespace restriction is
not in place.
This workaround means that every time an application creates a
QQuickView (and thus new QML engine) and loads a QML file that imports
QQC2, we end up calling initializeEngine(), as opposed to
registerTypes() that is called only one single time in the application
process. As a consequence each time this happens we and up calling
qmlRegisterTypes() with the same times and leak memory this way, as
qmlRegisterType*() is supposed to register a new type and return a new
type id that can be passed to qmlUnregisterType.
To solve this this patch lifts the restriction on namespaces for
registered types during registerTypes(). The real world case of QQC2
shows that the restriction is limiting and also easy to work around.
With the restriction lifted QQC2 can now register all types once in
registerTypes() instead.
[ChangeLog][QtQml][Important Behavior Changes] QML module plugins used
to be limited to type registrations in the primary module namespace in
the virtual registerTypes() function. Module authors worked around this
limitation by placing necessary internal type registrations into
initializeEngine() that may cause memory leaks. Therefore this
restriction has been moved and types in any (non-protected) namespaces
can be registered in the registerTypes() function.
Change-Id: I5baf9718a0b0a591f6eb6d7e2dc83e13b204800d
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlmoduleplugin')
5 files changed, 0 insertions, 77 deletions
diff --git a/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/invalidStrictModule.pro b/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/invalidStrictModule.pro deleted file mode 100644 index 150f2f08d3..0000000000 --- a/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/invalidStrictModule.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -SOURCES = plugin.cpp -QT = core qml -DESTDIR = ../imports/org/qtproject/InvalidStrictModule - -QT += core-private gui-private qml-private - -IMPORT_FILES = \ - qmldir - -include (../../../shared/imports.pri) diff --git a/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/plugin.cpp b/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/plugin.cpp deleted file mode 100644 index fe01507412..0000000000 --- a/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/plugin.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <QStringList> -#include <QtQml/qqmlextensionplugin.h> -#include <QtQml/qqml.h> -#include <QDebug> - -class MyPluginType : public QObject -{ - Q_OBJECT -public: - MyPluginType(QObject *parent=0) : QObject(parent) {} -}; - - -class MyPlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) - -public: - MyPlugin() {} - - void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == "org.qtproject.InvalidStrictModule"); - qmlRegisterType<MyPluginType>("org.qtproject.SomeOtherModule", 1, 0, "MyPluginType"); - } -}; - -#include "plugin.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/qmldir b/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/qmldir deleted file mode 100644 index 20716dc9f9..0000000000 --- a/tests/auto/qml/qqmlmoduleplugin/invalidStrictModule/qmldir +++ /dev/null @@ -1,2 +0,0 @@ -module org.qtproject.InvalidStrictModule -plugin invalidStrictModule diff --git a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro index 0f548aa6f8..ae13a041cc 100644 --- a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro +++ b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro @@ -11,7 +11,6 @@ SUBDIRS =\ nestedPlugin\ strictModule\ strictModule.2\ - invalidStrictModule\ nonstrictModule\ preemptiveModule\ preemptedStrictModule\ diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index 8600e1e8ab..edfbf57e76 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -506,12 +506,6 @@ void tst_qqmlmoduleplugin::importStrictModule_data() << QString() << QString(); - QTest::newRow("wrong target") - << "import org.qtproject.InvalidStrictModule 1.0\n" - "MyPluginType {}" - << QString() - << ":1:1: plugin cannot be loaded for module \"org.qtproject.InvalidStrictModule\": Cannot install element 'MyPluginType' into unregistered namespace 'org.qtproject.SomeOtherModule'"; - QTest::newRow("non-strict clash") << "import org.qtproject.NonstrictModule 1.0\n" "MyPluginType {}" |