summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/declarative/plugins/plugin.cpp7
-rw-r--r--src/declarative/qml/qmlengine.cpp4
-rw-r--r--src/declarative/qml/qmlmoduleplugin.cpp26
-rw-r--r--src/declarative/qml/qmlmoduleplugin.h8
4 files changed, 41 insertions, 4 deletions
diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp
index 9688caf..f4aa36b 100644
--- a/examples/declarative/plugins/plugin.cpp
+++ b/examples/declarative/plugins/plugin.cpp
@@ -138,7 +138,6 @@ MinuteTimer *Time::timer=0;
QML_DECLARE_TYPE(Time);
-QML_DEFINE_TYPE(com.nokia.TimeExample,1,0,Time,Time);
class QExampleQmlPlugin : public QmlModulePlugin
@@ -149,6 +148,12 @@ public:
{
return QStringList() << QLatin1String("com.nokia.TimeExample");
}
+
+ void defineModule(const QString& uri)
+ {
+ Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample"));
+ qmlRegisterType<Time>("com.nokia.TimeExample", 1, 0, "Time", "Time");
+ }
};
#include "plugin.moc"
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index b3ac1bb..a33aea7 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -1234,8 +1234,10 @@ public:
QFactoryLoader *l = loader();
QmlModuleFactoryInterface *factory =
qobject_cast<QmlModuleFactoryInterface*>(l->instance(uri));
- if (factory)
+ if (factory) {
+ factory->defineModuleOnce(uri);
isbuiltin = true;
+ }
} else {
url = base.resolved(QUrl(url)).toString();
}
diff --git a/src/declarative/qml/qmlmoduleplugin.cpp b/src/declarative/qml/qmlmoduleplugin.cpp
index 3346ec7..2f2cb25 100644
--- a/src/declarative/qml/qmlmoduleplugin.cpp
+++ b/src/declarative/qml/qmlmoduleplugin.cpp
@@ -59,11 +59,12 @@ QT_BEGIN_NAMESPACE
exporting the class with the Q_EXPORT_PLUGIN2() macro. See \l{How
to Create Qt Plugins} for details.
- The plugin should register QML types with QML_DEFINE_TYPE.
-
The strings returned by keys() should be the list of URIs of modules
that the plugin registers.
+ The plugin should register QML types with qmlRegisterType() when the
+ defineModule() method is called.
+
\sa examples/declarative/plugins
*/
@@ -86,4 +87,25 @@ QmlModulePlugin::~QmlModulePlugin()
{
}
+/*!
+ \fn void QmlModulePlugin::defineModule(const QString& uri)
+
+ Subclasses must override this function to register types
+ of the module \a uri, which will be one of the strings returned by keys().
+
+ The plugin registers QML types with qmlRegisterType():
+
+ \code
+ qmlRegisterType<MyClass>("com.nokia.MyModule", 1, 0, "MyType", "MyClass");
+ \endcode
+*/
+
+void QmlModulePlugin::defineModuleOnce(const QString& uri)
+{
+ if (!defined.contains(uri)) {
+ defined += uri;
+ defineModule(uri);
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlmoduleplugin.h b/src/declarative/qml/qmlmoduleplugin.h
index 315209d..384e05e 100644
--- a/src/declarative/qml/qmlmoduleplugin.h
+++ b/src/declarative/qml/qmlmoduleplugin.h
@@ -45,6 +45,7 @@
#include <QtCore/qplugin.h>
#include <QtCore/qfactoryinterface.h>
#include <QtCore/qlist.h>
+#include <QtCore/qset.h>
#include <QtCore/qbytearray.h>
QT_BEGIN_HEADER
@@ -55,6 +56,7 @@ QT_MODULE(Declarative)
struct Q_DECLARATIVE_EXPORT QmlModuleFactoryInterface : public QFactoryInterface
{
+ virtual void defineModuleOnce(const QString& uri) = 0;
};
#define QmlModuleFactoryInterface_iid "com.nokia.Qt.QmlModuleFactoryInterface"
@@ -69,6 +71,12 @@ class Q_DECLARATIVE_EXPORT QmlModulePlugin : public QObject, public QmlModuleFac
public:
explicit QmlModulePlugin(QObject *parent = 0);
~QmlModulePlugin();
+
+ virtual void defineModule(const QString& uri) = 0;
+
+private:
+ void defineModuleOnce(const QString& uri);
+ QSet<QString> defined;
};
QT_END_NAMESPACE