PDA

View Full Version : QML Loader



scgrant327
6th April 2016, 14:02
In my mobile app, I want to load a 'default' page from my main.cpp:


X.engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

I use my main.qml as a 'container' for all the pages of my app. Right now, I have them all defined in main.qml:


Rectangle {
id: winRect
visible: true
anchors.right: parent.right
anchors.left: parent.left
anchors.top: header.bottom
anchors.bottom: footer.top
color: "black"

MainWin {
id: mainWin
anchors.fill: parent
visible: false;
z: 0;
}

InfoWin {
id: infoWin
anchors.fill: parent
visible: false;
z: 0;
}

SettingsWin {
id: settingsWin
anchors.fill: parent
visible: false;
z: 0;
}

FileInfoWin {
id: fileInfoWin
anchors.fill: parent
visible: false;
z: 0;
}

BusyWin {
id: busyWin
anchors.fill: parent
visible: false;
z: 0;
}

ErrorWin {
id: errorWin
anchors.fill: parent
visible: false;
z: 0;
}
}

Then, later, via JavaScript, I 'show' the desired page by setting all 'visible' to false, then to true on the correct page. This all works fine...but causes a really slow startup time on iOS. I believe it is due to ALL my sub-pages being loaded at boot-time.

My question is... How can I use a Loader to load each page on demand, but still be able to access the attributes of each page when it is not loaded? For instance, I have Speed and Heading that get updated on two different pages every second or so. If a page is not "loaded" by the Loader, how can I update it's attributes?

IF that is not possible, then how can I detect when a page has fully loaded? As I understand it, the OnCompleted signal does not necessarily fire AFTER a component has been fully loaded.

--Sam

anda_skoa
6th April 2016, 15:23
The Loader has an onLoaded signal.

You can also use a Binding element to create bindings to the loaded item's properties.
Or you let the page content elements bind to the source directly.

Cheers,
_