aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-07-21 09:53:40 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-07-21 12:57:50 +0000
commit1c47598308d6399294114e5a5127a2373435802e (patch)
treeeb1845d4f420e0334bd5ee725d2ba85fe7665a99
parent531c757f300119d237bab5e72ccb762b7ed86e19 (diff)
Adjust import documentation to mention that versions are optional
This change also removes the versions from the import statements. Task-number: QTBUG-95302 Change-Id: Ie29e57a618917977b46dff25d13e3ca3eff249b5 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 58783a4f9d411e4bc0fc45bd5da9164e3313f0a3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/doc/snippets/qml/imports/merged-named-imports.qml4
-rw-r--r--src/qml/doc/src/qmllanguageref/syntax/imports.qdoc35
2 files changed, 24 insertions, 15 deletions
diff --git a/src/qml/doc/snippets/qml/imports/merged-named-imports.qml b/src/qml/doc/snippets/qml/imports/merged-named-imports.qml
index 8fab0436bd..533b22cb93 100644
--- a/src/qml/doc/snippets/qml/imports/merged-named-imports.qml
+++ b/src/qml/doc/snippets/qml/imports/merged-named-imports.qml
@@ -49,8 +49,8 @@
****************************************************************************/
//! [imports]
-import QtQuick 2.0 as Project
-import QtMultimedia 5.0 as Project
+import QtQuick as Project
+import QtMultimedia as Project
Project.Rectangle {
width: 100; height: 50
diff --git a/src/qml/doc/src/qmllanguageref/syntax/imports.qdoc b/src/qml/doc/src/qmllanguageref/syntax/imports.qdoc
index 14a99c44f4..ee104af29a 100644
--- a/src/qml/doc/src/qmllanguageref/syntax/imports.qdoc
+++ b/src/qml/doc/src/qmllanguageref/syntax/imports.qdoc
@@ -49,7 +49,7 @@ types and JavaScript resources into a given namespace.
The generic form of a module import is as follows:
\code
-import <ModuleIdentifier> <Version.Number> [as <Qualifier>]
+import <ModuleIdentifier> [<Version.Number>] [as <Qualifier>]
\endcode
\list
@@ -59,7 +59,9 @@ import <ModuleIdentifier> <Version.Number> [as <Qualifier>]
\li The \c <Version.Number> is a version of the form
\c {MajorVersion.MinorVersion} which specifies which definitions of
various object types and JavaScript resources will be made available due
- to the import.
+ to the import. It can be omitted, in which case the latest version of the
+ module is imported. It is also possible to only omit the minor version.
+ Then the latest minor version of the given major version is imported.
\li The \c <Qualifier> is an optional local namespace identifier into which
the object types and JavaScript resources provided by the module will be
installed, if given. If omitted, the object types and JavaScript
@@ -69,7 +71,7 @@ import <ModuleIdentifier> <Version.Number> [as <Qualifier>]
An example of an unqualified module import is as follows:
\code
-import QtQuick 2.0
+import QtQuick
\endcode
This import allows the use of all of the types provided by the \c QtQuick
@@ -77,7 +79,7 @@ module without needing to specify a qualifier. For example, the client code to
create a rectangle is as follows:
\qml
-import QtQuick 2.0
+import QtQuick
Rectangle {
width: 200
@@ -86,9 +88,16 @@ Rectangle {
}
\endqml
+An example of an unqualified import with version would be
+\code
+import QtQuick 2.10
+\endcode
+In that case, any types defined in QtQuick 2.11 and higher or in any higher major
+version, like 6.0, would not be available to the file.
+
An example of a qualified module import is as follows:
\code
-import QtQuick 2.0 as Quick
+import QtQuick as Quick
\endcode
This import allows multiple modules which provide conflicting type names to be
@@ -100,7 +109,7 @@ An example of client code which creates a rectangle after using a qualified
module import is as follows:
\qml
-import QtQuick 2.0 as Quick
+import QtQuick as Quick
Quick.Rectangle {
width: 200
@@ -149,7 +158,7 @@ references to types from the \c QtQuick module must be prefixed with the
\c CoreItems name:
\qml
-import QtQuick 2.0 as CoreItems
+import QtQuick as CoreItems
CoreItems.Rectangle {
width: 100; height: 100
@@ -171,7 +180,7 @@ two modules can be imported into different namespaces to ensure the code is
referring to the correct type:
\qml
-import QtQuick 2.0 as CoreItems
+import QtQuick as CoreItems
import "../textwidgets" as MyModule
CoreItems.Rectangle {
@@ -244,8 +253,8 @@ module by importing the module and using the identifier associated with a
declared resource:
\qml
-import QtQuick 2.0
-import projects.MyQMLProject.MyFunctions 1.0
+import QtQuick
+import projects.MyQMLProject.MyFunctions
Item {
Component.onCompleted: { SystemFunctions.cleanUp(); }
@@ -257,9 +266,9 @@ resource identifiers must be prefixed with the namespace qualifier in order
to be used:
\qml
-import QtQuick 2.0
-import projects.MyQMLProject.MyFunctions 1.0 as MyFuncs
-import org.example.Functions 1.0 as TheirFuncs
+import QtQuick
+import projects.MyQMLProject.MyFunctions as MyFuncs
+import org.example.Functions as TheirFuncs
Item {
Component.onCompleted: {