diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-04-28 11:47:23 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-05-02 15:26:58 +0000 |
commit | 460d22f70165f905b51d1a60dc14370a424c998a (patch) | |
tree | 01758c99bdf140969da76334edac2cc713b38a89 /examples | |
parent | d152e45a819c9dc9531b2acd0827102a3d911b0c (diff) |
Port the QML reference examples to QML module usage
As a drive-by fix the example origin where applicable.
Task-number: PYSIDE-2206
Task-number: QTBUG-111033
Change-Id: If3b17435c17310c3f6c196f7653c7025ad359366
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
(cherry picked from commit fbb22873530c200b4ddb9b2da91764948bb9da71)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples')
57 files changed, 118 insertions, 85 deletions
diff --git a/examples/qml/referenceexamples/adding/example.qml b/examples/qml/referenceexamples/adding/People/Main.qml index 42d47dea9..8d963a861 100644 --- a/examples/qml/referenceexamples/adding/example.qml +++ b/examples/qml/referenceexamples/adding/People/Main.qml @@ -1,7 +1,7 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import examples.adding.people +import People Person { name: "Bob Jones" diff --git a/examples/qml/referenceexamples/adding/People/qmldir b/examples/qml/referenceexamples/adding/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/adding/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/adding/adding.pyproject b/examples/qml/referenceexamples/adding/adding.pyproject index 46df4b253..3219f79ca 100644 --- a/examples/qml/referenceexamples/adding/adding.pyproject +++ b/examples/qml/referenceexamples/adding/adding.pyproject @@ -1,5 +1,4 @@ { - "files": ["example.qml", - "main.py", - "person.py"] + "files": ["main.py", "person.py", + "People/Main.qml", "People/qmldir"] } diff --git a/examples/qml/referenceexamples/adding/doc/adding.rst b/examples/qml/referenceexamples/adding/doc/adding.rst index 55f6105b7..d06ff0a5a 100644 --- a/examples/qml/referenceexamples/adding/doc/adding.rst +++ b/examples/qml/referenceexamples/adding/doc/adding.rst @@ -33,7 +33,7 @@ return members of the object instance. # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) - QML_IMPORT_NAME = "examples.adding.people" + QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/adding/main.py b/examples/qml/referenceexamples/adding/main.py index f10b77bc1..faf13f42f 100644 --- a/examples/qml/referenceexamples/adding/main.py +++ b/examples/qml/referenceexamples/adding/main.py @@ -6,7 +6,7 @@ from pathlib import Path import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine from person import Person @@ -15,10 +15,10 @@ from person import Person if __name__ == '__main__': app = QCoreApplication(sys.argv) - qml_file = Path(__file__).parent / "example.qml" - url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() - component = QQmlComponent(engine, url) + engine.addImportPath(Path(__file__).parent) + component = QQmlComponent(engine) + component.loadFromModule("People", "Main") person = component.create() if person: diff --git a/examples/qml/referenceexamples/adding/person.py b/examples/qml/referenceexamples/adding/person.py index 0c2b5b124..fafb9d581 100644 --- a/examples/qml/referenceexamples/adding/person.py +++ b/examples/qml/referenceexamples/adding/person.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlElement # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.adding.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/attached/example.qml b/examples/qml/referenceexamples/attached/People/Main.qml index f038b3ece..795d63867 100644 --- a/examples/qml/referenceexamples/attached/example.qml +++ b/examples/qml/referenceexamples/attached/People/Main.qml @@ -1,7 +1,7 @@ // Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import examples.default.people +import People BirthdayParty { Boy { diff --git a/examples/qml/referenceexamples/attached/People/qmldir b/examples/qml/referenceexamples/attached/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/attached/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/attached/attached.pyproject b/examples/qml/referenceexamples/attached/attached.pyproject index 3c01c40c2..09942ebcc 100644 --- a/examples/qml/referenceexamples/attached/attached.pyproject +++ b/examples/qml/referenceexamples/attached/attached.pyproject @@ -1,3 +1,4 @@ { - "files": ["main.py", "birthdayparty.py", "person.py", "example.qml"] + "files": ["main.py", "birthdayparty.py", "person.py", + "People/Main.qml", "People/qmldir"] } diff --git a/examples/qml/referenceexamples/attached/birthdayparty.py b/examples/qml/referenceexamples/attached/birthdayparty.py index d83236e26..63e86c3e0 100644 --- a/examples/qml/referenceexamples/attached/birthdayparty.py +++ b/examples/qml/referenceexamples/attached/birthdayparty.py @@ -9,7 +9,7 @@ from person import Person # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.default.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/attached/main.py b/examples/qml/referenceexamples/attached/main.py index d7483559f..bb607ac76 100644 --- a/examples/qml/referenceexamples/attached/main.py +++ b/examples/qml/referenceexamples/attached/main.py @@ -1,12 +1,12 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/referenceexamples/attached example from Qt v6.x""" +"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties example from Qt v6.x""" from pathlib import Path import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine, qmlAttachedPropertiesObject from person import Boy, Girl @@ -14,10 +14,10 @@ from birthdayparty import BirthdayParty app = QCoreApplication(sys.argv) -qml_file = Path(__file__).parent / "example.qml" -url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() -component = QQmlComponent(engine, url) +engine.addImportPath(Path(__file__).parent) +component = QQmlComponent(engine) +component.loadFromModule("People", "Main") party = component.create() if not party: print(component.errors()) diff --git a/examples/qml/referenceexamples/attached/person.py b/examples/qml/referenceexamples/attached/person.py index 7164bd645..89844c87f 100644 --- a/examples/qml/referenceexamples/attached/person.py +++ b/examples/qml/referenceexamples/attached/person.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlAnonymous, QmlElement # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.default.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/binding/example.qml b/examples/qml/referenceexamples/binding/People/Main.qml index ca0958810..75add22af 100644 --- a/examples/qml/referenceexamples/binding/example.qml +++ b/examples/qml/referenceexamples/binding/People/Main.qml @@ -1,7 +1,7 @@ // Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import examples.binding.people +import People BirthdayParty { id: theParty diff --git a/examples/qml/referenceexamples/binding/People/qmldir b/examples/qml/referenceexamples/binding/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/binding/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/binding/binding.pyproject b/examples/qml/referenceexamples/binding/binding.pyproject index a782d5c8a..fe2980fa9 100644 --- a/examples/qml/referenceexamples/binding/binding.pyproject +++ b/examples/qml/referenceexamples/binding/binding.pyproject @@ -1,3 +1,4 @@ { - "files": ["main.py", "birthdayparty.py", "happybirthdaysong.py", "person.py", "example.qml"] + "files": ["main.py", "birthdayparty.py", "happybirthdaysong.py", "person.py", + "People/Main.qml", "People/qmldir"] } diff --git a/examples/qml/referenceexamples/binding/birthdayparty.py b/examples/qml/referenceexamples/binding/birthdayparty.py index 78f0314b4..a337d4a16 100644 --- a/examples/qml/referenceexamples/binding/birthdayparty.py +++ b/examples/qml/referenceexamples/binding/birthdayparty.py @@ -9,7 +9,7 @@ from person import Person # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.binding.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.py b/examples/qml/referenceexamples/binding/happybirthdaysong.py index 80b288d81..59ebfe4c6 100644 --- a/examples/qml/referenceexamples/binding/happybirthdaysong.py +++ b/examples/qml/referenceexamples/binding/happybirthdaysong.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlElement, QPyQmlPropertyValueSource # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.binding.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/binding/main.py b/examples/qml/referenceexamples/binding/main.py index dcbd547ad..738bab086 100644 --- a/examples/qml/referenceexamples/binding/main.py +++ b/examples/qml/referenceexamples/binding/main.py @@ -6,7 +6,7 @@ from pathlib import Path import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine, qmlAttachedPropertiesObject from person import Boy, Girl @@ -16,10 +16,10 @@ from happybirthdaysong import HappyBirthdaySong if __name__ == "__main__": app = QCoreApplication(sys.argv) - qml_file = Path(__file__).parent / "example.qml" - url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() - component = QQmlComponent(engine, url) + engine.addImportPath(Path(__file__).parent) + component = QQmlComponent(engine) + component.loadFromModule("People", "Main") party = component.create() if not party: print(component.errors()) diff --git a/examples/qml/referenceexamples/binding/person.py b/examples/qml/referenceexamples/binding/person.py index 9e7d799e1..a6942763a 100644 --- a/examples/qml/referenceexamples/binding/person.py +++ b/examples/qml/referenceexamples/binding/person.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlAnonymous, QmlElement # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.binding.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/coercion/example.qml b/examples/qml/referenceexamples/coercion/People/Main.qml index c47678483..b2b7ace93 100644 --- a/examples/qml/referenceexamples/coercion/example.qml +++ b/examples/qml/referenceexamples/coercion/People/Main.qml @@ -1,7 +1,7 @@ // Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import examples.coercion.people +import People BirthdayParty { host: Boy { diff --git a/examples/qml/referenceexamples/coercion/People/qmldir b/examples/qml/referenceexamples/coercion/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/coercion/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/coercion/birthdayparty.py b/examples/qml/referenceexamples/coercion/birthdayparty.py index f6ad1ac35..47dddc85d 100644 --- a/examples/qml/referenceexamples/coercion/birthdayparty.py +++ b/examples/qml/referenceexamples/coercion/birthdayparty.py @@ -9,7 +9,7 @@ from person import Person # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.coercion.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/coercion/coercion.pyproject b/examples/qml/referenceexamples/coercion/coercion.pyproject index 3c01c40c2..09942ebcc 100644 --- a/examples/qml/referenceexamples/coercion/coercion.pyproject +++ b/examples/qml/referenceexamples/coercion/coercion.pyproject @@ -1,3 +1,4 @@ { - "files": ["main.py", "birthdayparty.py", "person.py", "example.qml"] + "files": ["main.py", "birthdayparty.py", "person.py", + "People/Main.qml", "People/qmldir"] } diff --git a/examples/qml/referenceexamples/coercion/main.py b/examples/qml/referenceexamples/coercion/main.py index 9f49bc1da..ef4b5ac5a 100644 --- a/examples/qml/referenceexamples/coercion/main.py +++ b/examples/qml/referenceexamples/coercion/main.py @@ -1,12 +1,13 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/referenceexamples/coercion example from Qt v6.x""" +"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion example from Qt v6.x""" from pathlib import Path +import os import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine from person import Boy, Girl @@ -14,10 +15,10 @@ from birthdayparty import BirthdayParty app = QCoreApplication(sys.argv) -qml_file = Path(__file__).parent / "example.qml" -url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() -component = QQmlComponent(engine, url) +engine.addImportPath(Path(__file__).parent) +component = QQmlComponent(engine) +component.loadFromModule("People", "Main") party = component.create() if not party: print(component.errors()) diff --git a/examples/qml/referenceexamples/coercion/person.py b/examples/qml/referenceexamples/coercion/person.py index 69056014c..189f2573e 100644 --- a/examples/qml/referenceexamples/coercion/person.py +++ b/examples/qml/referenceexamples/coercion/person.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlElement, QmlUncreatable # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.coercion.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/default/example.qml b/examples/qml/referenceexamples/default/People/Main.qml index 435be7860..9971a2315 100644 --- a/examples/qml/referenceexamples/default/example.qml +++ b/examples/qml/referenceexamples/default/People/Main.qml @@ -1,7 +1,7 @@ // Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import examples.default.people +import People BirthdayParty { host: Boy { diff --git a/examples/qml/referenceexamples/default/People/qmldir b/examples/qml/referenceexamples/default/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/default/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/default/birthdayparty.py b/examples/qml/referenceexamples/default/birthdayparty.py index 3c13ca6cf..8c6f7e8fb 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.py +++ b/examples/qml/referenceexamples/default/birthdayparty.py @@ -9,7 +9,7 @@ from person import Person # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.default.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/default/default.pyproject b/examples/qml/referenceexamples/default/default.pyproject index 3c01c40c2..09942ebcc 100644 --- a/examples/qml/referenceexamples/default/default.pyproject +++ b/examples/qml/referenceexamples/default/default.pyproject @@ -1,3 +1,4 @@ { - "files": ["main.py", "birthdayparty.py", "person.py", "example.qml"] + "files": ["main.py", "birthdayparty.py", "person.py", + "People/Main.qml", "People/qmldir"] } diff --git a/examples/qml/referenceexamples/default/main.py b/examples/qml/referenceexamples/default/main.py index a4ce2f08a..f469538b6 100644 --- a/examples/qml/referenceexamples/default/main.py +++ b/examples/qml/referenceexamples/default/main.py @@ -1,12 +1,12 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/referenceexamples/default example from Qt v6.x""" +"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/default advanced3-Default-properties example from Qt v6.x""" from pathlib import Path import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine from person import Boy, Girl @@ -14,10 +14,10 @@ from birthdayparty import BirthdayParty app = QCoreApplication(sys.argv) -qml_file = Path(__file__).parent / "example.qml" -url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() -component = QQmlComponent(engine, url) +engine.addImportPath(Path(__file__).parent) +component = QQmlComponent(engine) +component.loadFromModule("People", "Main") party = component.create() if not party: print(component.errors()) diff --git a/examples/qml/referenceexamples/default/person.py b/examples/qml/referenceexamples/default/person.py index 7164bd645..89844c87f 100644 --- a/examples/qml/referenceexamples/default/person.py +++ b/examples/qml/referenceexamples/default/person.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlAnonymous, QmlElement # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.default.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/grouped/example.qml b/examples/qml/referenceexamples/grouped/People/Main.qml index d0db4f193..3c34234fd 100644 --- a/examples/qml/referenceexamples/grouped/example.qml +++ b/examples/qml/referenceexamples/grouped/People/Main.qml @@ -3,7 +3,7 @@ import QtQuick -import examples.grouped.people +import People BirthdayParty { host: Boy { diff --git a/examples/qml/referenceexamples/grouped/People/qmldir b/examples/qml/referenceexamples/grouped/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/grouped/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.py b/examples/qml/referenceexamples/grouped/birthdayparty.py index 9f414441e..8c6f7e8fb 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.py +++ b/examples/qml/referenceexamples/grouped/birthdayparty.py @@ -9,7 +9,7 @@ from person import Person # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.grouped.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/grouped/grouped.pyproject b/examples/qml/referenceexamples/grouped/grouped.pyproject index 3c01c40c2..09942ebcc 100644 --- a/examples/qml/referenceexamples/grouped/grouped.pyproject +++ b/examples/qml/referenceexamples/grouped/grouped.pyproject @@ -1,3 +1,4 @@ { - "files": ["main.py", "birthdayparty.py", "person.py", "example.qml"] + "files": ["main.py", "birthdayparty.py", "person.py", + "People/Main.qml", "People/qmldir"] } diff --git a/examples/qml/referenceexamples/grouped/main.py b/examples/qml/referenceexamples/grouped/main.py index f1edb8b94..657ce272b 100644 --- a/examples/qml/referenceexamples/grouped/main.py +++ b/examples/qml/referenceexamples/grouped/main.py @@ -1,12 +1,12 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/referenceexamples/default example from Qt v6.x""" +"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties example from Qt v6.x""" from pathlib import Path import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine from person import Boy, Girl @@ -15,10 +15,11 @@ from birthdayparty import BirthdayParty if __name__ == '__main__': app = QCoreApplication(sys.argv) - qml_file = Path(__file__).parent / "example.qml" - url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() - component = QQmlComponent(engine, url) + engine.addImportPath(Path(__file__).parent) + component = QQmlComponent(engine) + component.loadFromModule("People", "Main") + party = component.create() if not party: print(component.errors()) diff --git a/examples/qml/referenceexamples/grouped/person.py b/examples/qml/referenceexamples/grouped/person.py index a1edf077e..42434fffa 100644 --- a/examples/qml/referenceexamples/grouped/person.py +++ b/examples/qml/referenceexamples/grouped/person.py @@ -7,7 +7,7 @@ from PySide6.QtQml import QmlAnonymous, QmlElement # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.grouped.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/methods/example.qml b/examples/qml/referenceexamples/methods/People/Main.qml index c48e952fd..69b2119ab 100644 --- a/examples/qml/referenceexamples/methods/example.qml +++ b/examples/qml/referenceexamples/methods/People/Main.qml @@ -2,7 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick -import examples.methods.people +import People BirthdayParty { host: Person { diff --git a/examples/qml/referenceexamples/methods/People/qmldir b/examples/qml/referenceexamples/methods/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/methods/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/methods/birthdayparty.py b/examples/qml/referenceexamples/methods/birthdayparty.py index 41425a2b1..a3942b671 100644 --- a/examples/qml/referenceexamples/methods/birthdayparty.py +++ b/examples/qml/referenceexamples/methods/birthdayparty.py @@ -9,7 +9,7 @@ from person import Person # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.methods.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/methods/main.py b/examples/qml/referenceexamples/methods/main.py index 31748ff2b..5f51ebe1f 100644 --- a/examples/qml/referenceexamples/methods/main.py +++ b/examples/qml/referenceexamples/methods/main.py @@ -6,7 +6,7 @@ from pathlib import Path import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine from person import Person @@ -14,10 +14,10 @@ from birthdayparty import BirthdayParty app = QCoreApplication(sys.argv) -qml_file = Path(__file__).parent / "example.qml" -url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() -component = QQmlComponent(engine, url) +engine.addImportPath(Path(__file__).parent) +component = QQmlComponent(engine) +component.loadFromModule("People", "Main") party = component.create() if not party: print(component.errors()) diff --git a/examples/qml/referenceexamples/methods/methods.pyproject b/examples/qml/referenceexamples/methods/methods.pyproject index 3c01c40c2..09942ebcc 100644 --- a/examples/qml/referenceexamples/methods/methods.pyproject +++ b/examples/qml/referenceexamples/methods/methods.pyproject @@ -1,3 +1,4 @@ { - "files": ["main.py", "birthdayparty.py", "person.py", "example.qml"] + "files": ["main.py", "birthdayparty.py", "person.py", + "People/Main.qml", "People/qmldir"] } diff --git a/examples/qml/referenceexamples/methods/person.py b/examples/qml/referenceexamples/methods/person.py index b5e0bd899..526eae714 100644 --- a/examples/qml/referenceexamples/methods/person.py +++ b/examples/qml/referenceexamples/methods/person.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlElement # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.methods.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/properties/example.qml b/examples/qml/referenceexamples/properties/People/Main.qml index 1486a0f92..0600b3557 100644 --- a/examples/qml/referenceexamples/properties/example.qml +++ b/examples/qml/referenceexamples/properties/People/Main.qml @@ -1,7 +1,7 @@ // Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import examples.properties.people +import People BirthdayParty { host: Person { diff --git a/examples/qml/referenceexamples/properties/People/qmldir b/examples/qml/referenceexamples/properties/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/properties/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/properties/birthdayparty.py b/examples/qml/referenceexamples/properties/birthdayparty.py index 1a115101b..47dddc85d 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.py +++ b/examples/qml/referenceexamples/properties/birthdayparty.py @@ -9,7 +9,7 @@ from person import Person # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.properties.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/properties/doc/properties.rst b/examples/qml/referenceexamples/properties/doc/properties.rst index 909434c3c..fd0c6d474 100644 --- a/examples/qml/referenceexamples/properties/doc/properties.rst +++ b/examples/qml/referenceexamples/properties/doc/properties.rst @@ -40,7 +40,7 @@ The BirthdayParty class is declared like this: # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) - QML_IMPORT_NAME = "examples.properties.people" + QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/properties/main.py b/examples/qml/referenceexamples/properties/main.py index a980b25aa..4797e4c7c 100644 --- a/examples/qml/referenceexamples/properties/main.py +++ b/examples/qml/referenceexamples/properties/main.py @@ -6,7 +6,7 @@ from pathlib import Path import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine from person import Person @@ -16,10 +16,10 @@ from birthdayparty import BirthdayParty if __name__ == '__main__': app = QCoreApplication(sys.argv) - qml_file = Path(__file__).parent / "example.qml" - url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() - component = QQmlComponent(engine, url) + engine.addImportPath(Path(__file__).parent) + component = QQmlComponent(engine) + component.loadFromModule("People", "Main") party = component.create() if party: diff --git a/examples/qml/referenceexamples/properties/person.py b/examples/qml/referenceexamples/properties/person.py index 4cc54260a..fafb9d581 100644 --- a/examples/qml/referenceexamples/properties/person.py +++ b/examples/qml/referenceexamples/properties/person.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlElement # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.properties.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/properties/properties.pyproject b/examples/qml/referenceexamples/properties/properties.pyproject index 0f5958fc3..adb34b2d0 100644 --- a/examples/qml/referenceexamples/properties/properties.pyproject +++ b/examples/qml/referenceexamples/properties/properties.pyproject @@ -1,6 +1,4 @@ { - "files": ["example.qml", - "main.py", - "person.py", - "birthdayparty.py"] + "files": ["main.py", "person.py", "birthdayparty.py", + "People/Main.qml", "People/qmldir"] } diff --git a/examples/qml/referenceexamples/valuesource/example.qml b/examples/qml/referenceexamples/valuesource/People/Main.qml index cb9683f3a..254265a80 100644 --- a/examples/qml/referenceexamples/valuesource/example.qml +++ b/examples/qml/referenceexamples/valuesource/People/Main.qml @@ -1,7 +1,7 @@ // Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import examples.valuesource.people +import People BirthdayParty { HappyBirthdaySong on announcement { name: "Bob Jones" } diff --git a/examples/qml/referenceexamples/valuesource/People/qmldir b/examples/qml/referenceexamples/valuesource/People/qmldir new file mode 100644 index 000000000..a2bd9515a --- /dev/null +++ b/examples/qml/referenceexamples/valuesource/People/qmldir @@ -0,0 +1,3 @@ +module People +typeinfo coercion.qmltypes +Main 1.0 Main.qml diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.py b/examples/qml/referenceexamples/valuesource/birthdayparty.py index 3bc75e819..52af2fe97 100644 --- a/examples/qml/referenceexamples/valuesource/birthdayparty.py +++ b/examples/qml/referenceexamples/valuesource/birthdayparty.py @@ -9,7 +9,7 @@ from person import Person # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.valuesource.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/valuesource/happybirthdaysong.py b/examples/qml/referenceexamples/valuesource/happybirthdaysong.py index 30aa6b59b..59ebfe4c6 100644 --- a/examples/qml/referenceexamples/valuesource/happybirthdaysong.py +++ b/examples/qml/referenceexamples/valuesource/happybirthdaysong.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlElement, QPyQmlPropertyValueSource # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.valuesource.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/valuesource/main.py b/examples/qml/referenceexamples/valuesource/main.py index c3ded4be9..b763a456a 100644 --- a/examples/qml/referenceexamples/valuesource/main.py +++ b/examples/qml/referenceexamples/valuesource/main.py @@ -1,12 +1,12 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/referenceexamples/valuesource example from Qt v6.x""" +"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source example from Qt v6.x""" from pathlib import Path import sys -from PySide6.QtCore import QCoreApplication, QUrl +from PySide6.QtCore import QCoreApplication from PySide6.QtQml import QQmlComponent, QQmlEngine, qmlAttachedPropertiesObject from person import Boy, Girl @@ -15,10 +15,10 @@ from happybirthdaysong import HappyBirthdaySong app = QCoreApplication(sys.argv) -qml_file = Path(__file__).parent / "example.qml" -url = QUrl.fromLocalFile(qml_file) engine = QQmlEngine() -component = QQmlComponent(engine, url) +engine.addImportPath(Path(__file__).parent) +component = QQmlComponent(engine) +component.loadFromModule("People", "Main") party = component.create() if not party: print(component.errors()) diff --git a/examples/qml/referenceexamples/valuesource/person.py b/examples/qml/referenceexamples/valuesource/person.py index 5cd04e38a..89844c87f 100644 --- a/examples/qml/referenceexamples/valuesource/person.py +++ b/examples/qml/referenceexamples/valuesource/person.py @@ -6,7 +6,7 @@ from PySide6.QtQml import QmlAnonymous, QmlElement # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.valuesource.people" +QML_IMPORT_NAME = "People" QML_IMPORT_MAJOR_VERSION = 1 diff --git a/examples/qml/referenceexamples/valuesource/valuesource.pyproject b/examples/qml/referenceexamples/valuesource/valuesource.pyproject index a782d5c8a..fe2980fa9 100644 --- a/examples/qml/referenceexamples/valuesource/valuesource.pyproject +++ b/examples/qml/referenceexamples/valuesource/valuesource.pyproject @@ -1,3 +1,4 @@ { - "files": ["main.py", "birthdayparty.py", "happybirthdaysong.py", "person.py", "example.qml"] + "files": ["main.py", "birthdayparty.py", "happybirthdaysong.py", "person.py", + "People/Main.qml", "People/qmldir"] } |