Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Problems Loading Mock Data with qmlscene
Forum Updated to NodeBB v4.3 + New Features

Problems Loading Mock Data with qmlscene

Scheduled Pinned Locked Moved Qt Creator and other tools
2 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dbrian
    wrote on last edited by
    #1

    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.2

    Rectangle {
    implicitHeight: 1280
    implicitWidth: 1024

    ListView {
        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.0

    QtObject {
    id: model

    property 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.0

    QtObject {
    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!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      Hi,

      How does your main.qml look like with the mock data?

      Are you still using this:

      @ // main.qml
      import QtQuick 2.2

      Rectangle {
          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.0

      Item {
      width: 360
      height: 360

      Runtime {
          id: runtime
      }
      
      ListView {
          anchors.fill: parent
          model: runtime.availableScanners
          delegate: Rectangle {
              width: 60
              height: 60
              Text {
                  anchors.fill: parent
                  text: serialNumber
              }
          }
      }
      

      }@

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved