Problems Loading Mock Data with qmlscene
-
I'm having some problems figuring out how the loading scheme works for 'dummy data' when prototyping with qmlscene. Hoping someone can help me out.
I have a pretty basic main qml file that expects a context property 'runtime'. This object has a sub property 'availableScanners', which is a list of QObject-derived pointers wrapped by a QQmlListProperty.
@
// main.qml
import QtQuick 2.2Rectangle {
implicitHeight: 1280
implicitWidth: 1024ListView { model: runtime.availableScanners }
}
@I'm trying to set up some dummy data so that I can tweak the front end without having to rely on a C++ backend every time I run. I've set up a 'dummydata' folder in the same directory as main.qml, containing two files: runtime.qml and MockScanner.qml. The files are defined as follows:
@
//runtime.qml
import QtQuick 2.0QtObject {
id: modelproperty list<MockScanner> availableScanners: [ MockScanner { serialNumber: "xxxxxx08" connectionState: "UnconnectedState" }, MockScanner { serialNumber: "xxxxxx08" connectionState: "UnconnectedState" }, MockScanner { serialNumber: "xxxxxx08" connectionState: "UnconnectedState" }, MockScanner { serialNumber: "xxxxxxx08" connectionState: "UnconnectedState" } ] Component.onCompleted: console.log('done: ', availableScanners[0].serialNumber);
}
@@
//MockScanner.qml
import QtQuick 2.0QtObject {
property string serialNumber: "SerialNo"
property string connectionState: "UnconnectedState"Component.onCompleted: console.log('Created Mock')
}
@When I try to run main.qml with qmlscene, the model will not load correctly and I get the following output:
@
Starting external tool 'qmlscene' (...)/Source/qml/main.qml
Created Mock
Loaded dummy data: "(...)/Source/qml/dummydata/MockScanner.qml"
QQmlComponent: Component is not ready
<Unknown File>: MockScanner is not a type
(...)/Source/qml/main.qml:263: ReferenceError: runtime is not defined
@The weird thing is that if I run either "runtime.qml" or "MockScanner.qml" within qmlscene, everything works fine (no complaints about MockScanner not being a type).
Am I doing something wrong or unsupported? Or is this potentially a problem with the qmlscene loading mechanism for dummy data? Any insight would be greatly appreciated.
Thanks!
-
Hi,
How does your main.qml look like with the mock data?
Are you still using this:
@ // main.qml
import QtQuick 2.2Rectangle { implicitHeight: 1280 implicitWidth: 1024 ListView { model: runtime.availableScanners } }
@
if so, try renaming "runtime.qml" to "Runtime.qml" and change your mail.qml to this:
@import QtQuick 2.0
import Minh 1.0Item {
width: 360
height: 360Runtime { id: runtime } ListView { anchors.fill: parent model: runtime.availableScanners delegate: Rectangle { width: 60 height: 60 Text { anchors.fill: parent text: serialNumber } } }
}@