diff options
author | Liang Qi <liang.qi@qt.io> | 2018-02-02 09:50:10 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-02-02 09:50:10 +0100 |
commit | 2e65f6c2a5d84f4369245cabdc03eca4c19851f0 (patch) | |
tree | ae662f1aca8dc42d4fbb309681c3051d6201ceb6 /src/qml/doc/src | |
parent | a8cff469b6f9055f084c31514481d08c11b5303b (diff) | |
parent | 6958308c09ceda855a30c5a2d491f078c5104071 (diff) |
Merge remote-tracking branch 'origin/5.9' into 5.10
Change-Id: I41ca9120a470a905c2f5c168c1de4cf970fa0fff
Diffstat (limited to 'src/qml/doc/src')
-rw-r--r-- | src/qml/doc/src/qmlfunctions.qdoc | 25 | ||||
-rw-r--r-- | src/qml/doc/src/qmllanguageref/syntax/basics.qdoc | 2 | ||||
-rw-r--r-- | src/qml/doc/src/qmllanguageref/typesystem/objecttypes.qdoc | 2 |
3 files changed, 29 insertions, 0 deletions
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc index 8a62a18eec..f939ddbcf3 100644 --- a/src/qml/doc/src/qmlfunctions.qdoc +++ b/src/qml/doc/src/qmlfunctions.qdoc @@ -324,6 +324,19 @@ qmlRegisterSingletonType("Qt.example.qjsvalueApi", 1, 0, "MyApi", example_qjsvalue_singletontype_provider); \endcode + Alternatively, you can use a C++11 lambda: + + \code + qmlRegisterSingletonType("Qt.example.qjsvalueApi", 1, 0, "MyApi", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QJSValue { + Q_UNUSED(engine) + + static int seedValue = 5; + QJSValue example = scriptEngine->newObject(); + example.setProperty("someProperty", seedValue++); + return example; + }); + \endcode + In order to use the registered singleton type in QML, you must import the singleton type. \qml import QtQuick 2.0 @@ -423,6 +436,18 @@ qmlRegisterSingletonType<SingletonTypeExample>("Qt.example.qobjectSingleton", 1, 0, "MyApi", example_qobject_singletontype_provider); \endcode + Alternatively, you can use a C++11 lambda: + + \code + qmlRegisterSingletonType<SingletonTypeExample>("Qt.example.qjsvalueApi", 1, 0, "MyApi", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + + SingletonTypeExample *example = new SingletonTypeExample(); + return example; + }); + \endcode + In order to use the registered singleton type in QML, you must import the singleton type. \qml import QtQuick 2.0 diff --git a/src/qml/doc/src/qmllanguageref/syntax/basics.qdoc b/src/qml/doc/src/qmllanguageref/syntax/basics.qdoc index 1b645a94c0..9eb8f72cf2 100644 --- a/src/qml/doc/src/qmllanguageref/syntax/basics.qdoc +++ b/src/qml/doc/src/qmllanguageref/syntax/basics.qdoc @@ -38,6 +38,8 @@ imperative code, in the case where complex custom application behavior is needed QML source code is generally loaded by the engine through QML \e documents, which are standalone documents of QML code. These can be used to define \l {QML Object Types}{QML object types} that can then be reused throughout an application. +Note that type names must begin with an uppercase letter in order +to be declared as QML object types in a QML file. \section1 Import Statements diff --git a/src/qml/doc/src/qmllanguageref/typesystem/objecttypes.qdoc b/src/qml/doc/src/qmllanguageref/typesystem/objecttypes.qdoc index b74646b7d0..5f089b5ebc 100644 --- a/src/qml/doc/src/qmllanguageref/typesystem/objecttypes.qdoc +++ b/src/qml/doc/src/qmllanguageref/typesystem/objecttypes.qdoc @@ -45,6 +45,8 @@ type, as discussed in \l {qtqml-documents-definetypes.html} {Documents as QML object type definitions}, or by defining a QML type from C++ and registering the type with the QML engine, as discussed in \l{qtqml-cppintegration-definetypes.html}{Defining QML Types from C++}. +Note that in both cases, the type name must begin with an uppercase letter in +order to be declared as a QML object type in a QML file. \section1 Defining Object Types from QML |