From c9330b0acf680d4c2a0933b8bf67dc9b3114de5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Mon, 28 Jun 2021 16:42:55 +0200 Subject: qml: replace context properties and code updates Most of the qml code in the repository was outdated, and followed bad practices, like context properties. Complementary, after the major updates for Qt6 most of the code was not relying on the new ways of register types (singletons, and using the decorator QmlElement). Drop the context property usage in the following examples: - signals/qmltopy1 - signals/qmltopy2 - signals/pytoqml2 - usingmodel - quickcontrols2/gallery - textproperties Additionally: - all the tests related to context properties - tutorials/qmlapp - tutorials/qmlsqlintegration - Removing 'scrolling' example - Fixing some flake8 warnings Change-Id: I649248c0149876bf2bf94e78e27cef7110f42f1d Reviewed-by: Friedemann Kleint Reviewed-by: Qt CI Bot Reviewed-by: Keith Kyzivat --- sources/pyside6/doc/tutorials/qmlsqlintegration/main.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sources/pyside6/doc/tutorials/qmlsqlintegration/main.py') diff --git a/sources/pyside6/doc/tutorials/qmlsqlintegration/main.py b/sources/pyside6/doc/tutorials/qmlsqlintegration/main.py index ac295bda0..3cd19e96e 100644 --- a/sources/pyside6/doc/tutorials/qmlsqlintegration/main.py +++ b/sources/pyside6/doc/tutorials/qmlsqlintegration/main.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2019 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the Qt for Python project. @@ -37,6 +37,7 @@ ## ############################################################################# +import sys import logging from PySide6.QtCore import QDir, QFile, QUrl @@ -44,7 +45,8 @@ from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine from PySide6.QtSql import QSqlDatabase -from sqlDialog import SqlConversationModel +# We import the file just to trigger the QmlElement type registration. +import sqlDialog logging.basicConfig(filename="chat.log", level=logging.DEBUG) logger = logging.getLogger("logger") @@ -57,7 +59,7 @@ def connectToDatabase(): if not database.isValid(): logger.error("Cannot add database") - write_dir = QDir() + write_dir = QDir("") if not write_dir.mkpath("."): logger.error("Failed to create writable directory") @@ -76,11 +78,11 @@ def connectToDatabase(): if __name__ == "__main__": app = QGuiApplication() connectToDatabase() - sql_conversation_model = SqlConversationModel() engine = QQmlApplicationEngine() - # Export pertinent objects to QML - engine.rootContext().setContextProperty("chat_model", sql_conversation_model) engine.load(QUrl("chat.qml")) + if not engine.rootObjects(): + sys.exit(-1) + app.exec() -- cgit v1.2.3