diff --git a/demo/demo.qml b/demo/demo.qml index fb799d5..29fd565 100644 --- a/demo/demo.qml +++ b/demo/demo.qml @@ -5,6 +5,16 @@ import QtQuick.Layouts 1.3 ApplicationWindow { id: application + property string initialTab: "style" + property int qtquickIndex: 0 + property var processes: ListModel { ListElement{ name: "init"} } + onInitialTabChanged: { + for (var i = 0; i < tabView.count; ++i) { + if (tabView.getTab(i).title === initialTab) { + tabView.currentIndex = i; + } + } + } width: 640 height: 480 visible: true @@ -19,13 +29,6 @@ ApplicationWindow { TabView { id: tabView anchors.fill: parent - onCountChanged: { - for (var i = 0; i < tabView.count; ++i) { - if (tabView.getTab(i).title === initialTab) { - tabView.currentIndex = i; - } - } - } Tab { title: "style" Column { @@ -36,7 +39,7 @@ ApplicationWindow { model: styles textRole: "display" onCurrentIndexChanged: { - if (currentIndex != qtquickIndex) { + if (currentIndex !== qtquickIndex) { widgets.currentIndex = currentIndex; application.close(); } diff --git a/demo/src/main.cpp b/demo/src/main.cpp index 7692eda..2dc2600 100644 --- a/demo/src/main.cpp +++ b/demo/src/main.cpp @@ -79,20 +79,20 @@ void createQtQuick(const QString& name, const QString& qml, Model* model, c->setContextProperty("styles", &model->styles); c->setContextProperty("demo", &model->demo); c->setContextProperty("sortedFileSystem", &model->sortedFileSystem); - c->setContextProperty("processes", &model->sortedProcesses); - c->setContextProperty("widgets", widgets); - c->setContextProperty("qtquickIndex", - QVariant(model->styles.stringList().indexOf(name))); - c->setContextProperty("initialTab", initialTab); QRect geometry; QWindow* window = getWindow(widgets); if (window) { geometry = window->geometry(); } engine->load(QUrl(qml)); - auto root = engine->rootObjects().first(); + QObject* root = engine->rootObjects().first(); copyWindowGeometry(geometry, root); + root->setProperty("initialTab", initialTab); + root->setProperty("qtquickIndex", + QVariant(model->styles.stringList().indexOf(name))); + root->setProperty("processes", + QVariant::fromValue(&model->sortedProcesses)); } #endif