×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    40

    separating XMLlistmodel as component leads to reference error

    hi,

    so I wanted to separate my data models as component(s) so it wouldn't cramped up on main.qml

    so i created a file called "xmlmodels.qml" and put it in the components folder and say with content on it,

    Code:
    import QtQuick 1.0
    
     XmlListModel {
         id: xmlModel
         source: "http://www.mysite.com/feed.xml"
         query: "/rss/channel/item"
    
         XmlRole { name: "title"; query: "title/string()" }
         XmlRole { name: "pubDate"; query: "pubDate/string()" }
     }
    and then my "main.qml" kinda looks like this

    Code:
    import QtQuick 1.0
    import "components"
    ListView {
                 id:homelv
                 anchors.fill: parent
                 model: xmlModel
                 delegate: some_delegate
             }
    
    ...
    ...
    but then when i run it, it would say,

    ReferenceError: Can't find variable: xmlModel

    any idea, on why it can't see the xmlModel variable? but all other QML components that's not XMLlistmodel can be loaded and referenced without a problem.

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: separating XMLlistmodel as component leads to reference error

    try using this
    Code:
    import QtQuick 1.0
    import "components"
    ListView {
                 id:homelv
                 anchors.fill: parent
                 model: xmlmodels
                 delegate: some_delegate
             }
    
    ...

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    40

    Re: separating XMLlistmodel as component leads to reference error

    reference error still persist.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    7

    Re: separating XMLlistmodel as component leads to reference error

    First rename XMLListModel file with like this (with capital): Xmlmodels.qml

    and use it like this:

    Code:
    import QtQuick 1.0
    import "components"
    ...
    ListView {
                 id:homelv
                 anchors.fill: parent
                 model: XmlModels {}
                 delegate: some_delegate
             }
    ...
    or like this:

    Code:
    import QtQuick 1.0
    import "components"
    ...
    XmlModels {id: xmlModel }
    ListView {
                 id:homelv
                 anchors.fill: parent
                 model: xmlModel
                 delegate: some_delegate
             }
    ...

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    40

    Re: separating XMLlistmodel as component leads to reference error

    thanks, this could really come in handy with my next app.

Similar Threads

  1. Text Field as a Component in Lwuit
    By kumarv75 in forum Mobile Java General
    Replies: 3
    Last Post: 2010-10-18, 18:25
  2. Images as list items & list as a component of a form
    By thijsman86 in forum Symbian User Interface
    Replies: 1
    Last Post: 2010-07-23, 20:00
  3. Image as reference to the project
    By lpinguin in forum Mobile Java General
    Replies: 3
    Last Post: 2006-11-13, 06:10
  4. PC connectivity SDK 2.1,Component Library reference-not completed
    By soonbee in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2003-05-14, 13:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •