From 90b4528b846542bfa6f0723487315140b9de17b4 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 17 Sep 2019 18:10:59 +0200 Subject: Avoid discouraged patterns in examples In particular, use required properties where applicable, explicitly import QtQml where we use it, avoid unqualified access into the root scope of a component, use JavaScript functions with explicit parameters as signal handlers. Change-Id: I3eaaba47cc3c7a2a12d488e36f9eec145cedbb0e Reviewed-by: Fabian Kosmale Reviewed-by: Shawn Rutledge --- examples/quick/models/abstractitemmodel/main.cpp | 4 +--- examples/quick/models/abstractitemmodel/view.qml | 10 ++++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'examples/quick/models/abstractitemmodel') diff --git a/examples/quick/models/abstractitemmodel/main.cpp b/examples/quick/models/abstractitemmodel/main.cpp index 515f47ec30..dd5b368c6b 100644 --- a/examples/quick/models/abstractitemmodel/main.cpp +++ b/examples/quick/models/abstractitemmodel/main.cpp @@ -68,10 +68,8 @@ int main(int argc, char ** argv) QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); - QQmlContext *ctxt = view.rootContext(); - ctxt->setContextProperty("myModel", &model); + view.setInitialProperties({{"model", QVariant::fromValue(&model)}}); //![0] - view.setSource(QUrl("qrc:view.qml")); view.show(); diff --git a/examples/quick/models/abstractitemmodel/view.qml b/examples/quick/models/abstractitemmodel/view.qml index f699aa40c8..2b9f87df92 100644 --- a/examples/quick/models/abstractitemmodel/view.qml +++ b/examples/quick/models/abstractitemmodel/view.qml @@ -53,8 +53,14 @@ import QtQuick 2.0 ListView { width: 200; height: 250 - model: myModel - delegate: Text { text: "Animal: " + type + ", " + size } + required model + + delegate: Text { + required property string type + required property string size + + text: "Animal: " + type + ", " + size + } } //![0] -- cgit v1.2.3