From 89e70719d9873c0e552d86533ee8f39c70270b7e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 8 Aug 2024 09:00:00 +0200 Subject: Documentation: Rewrite 'QML Integration' to use loadFromModule() As a drive-by, change the resource file name to the naming convention used by pyside6-project and fix some snippet lines. Pick-to: 6.7 Task-number: PYSIDE-2833 Change-Id: Id73b0584e45a58f20eb1a53892943119fe4db6a4 Reviewed-by: Shyamnath Premnadh Reviewed-by: Cristian Maureira-Fredes --- sources/pyside6/doc/tutorials/qmlintegration/main.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'sources/pyside6/doc/tutorials/qmlintegration/main.py') diff --git a/sources/pyside6/doc/tutorials/qmlintegration/main.py b/sources/pyside6/doc/tutorials/qmlintegration/main.py index b6c35c562..574e314de 100644 --- a/sources/pyside6/doc/tutorials/qmlintegration/main.py +++ b/sources/pyside6/doc/tutorials/qmlintegration/main.py @@ -3,14 +3,13 @@ from __future__ import annotations import sys -from pathlib import Path from PySide6.QtCore import QObject, Slot from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine, QmlElement from PySide6.QtQuickControls2 import QQuickStyle -import style_rc # noqa F401 +import rc_style # noqa F401 # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) @@ -53,11 +52,9 @@ if __name__ == '__main__': app = QGuiApplication(sys.argv) QQuickStyle.setStyle("Material") engine = QQmlApplicationEngine() - - # Get the path of the current directory, and then add the name - # of the QML file, to load it. - qml_file = Path(__file__).parent / 'view.qml' - engine.load(qml_file) + # Add the current directory to the import paths and load the main module. + engine.addImportPath(sys.path[0]) + engine.loadFromModule("Main", "Main") if not engine.rootObjects(): sys.exit(-1) -- cgit v1.2.3