From db336fa57497f837cfe9d58eb2d7763b33bef2e7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 15 Sep 2017 15:28:29 +0200 Subject: Quick examples: Standardize loading code Expand local file by directory of script and load via QUrl. Exit on error. Change-Id: Ia5fd36cbe9b8940e265968e91a5e5ec2b216276b Reviewed-by: Christian Tismer --- examples/declarative/usingmodel.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'examples/declarative/usingmodel.py') diff --git a/examples/declarative/usingmodel.py b/examples/declarative/usingmodel.py index cbb334e..7d73990 100644 --- a/examples/declarative/usingmodel.py +++ b/examples/declarative/usingmodel.py @@ -42,8 +42,9 @@ from __future__ import print_function +import os import sys -from PySide2.QtCore import QAbstractListModel, Qt +from PySide2.QtCore import QAbstractListModel, Qt, QUrl from PySide2.QtGui import QGuiApplication import PySide2.QtQml from PySide2.QtQuick import QQuickView @@ -89,7 +90,10 @@ if __name__ == '__main__': myModel.populate() view.rootContext().setContextProperty("myModel", myModel) - view.setSource('view.qml') + qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml') + view.setSource(QUrl.fromLocalFile(qmlFile)) + if view.status() == QQuickView.Error: + sys.exit(-1) view.show() app.exec_() -- cgit v1.2.3