Important: Please read the Qt Code of Conduct -

How to get XML attributes default value when use XmlListModel / XmlRole.

  • Hi,I am try QML.

    I have XML file .
    <node value="1" />
    <node value="2" option="x" />
    <node value="3" />

    ListView use, the XML file.

    XmlRole { name:"mValue"; query:"@value/number()" }
    XmlRole { name:"mOption"; query:"@option/string()" }

    I got Error....
    ReferenceError: Can't find variable: mOption

    I guess, anywhere have not default value of option attribute.

    do you have same idea?

    [edit] added code wrappings, koahnig

  • Can you show the bit of code producing the error? Note that the roles will only be available within a ListView delegate, so referencing them elsewhere might produce the type of error you are seeing.


  • Thinks for quick reply, Michael.

    I noticed that the spelling is wrong When i check again,today.

    and, XML Attributes is undefined, i confirmed the operation defaults to 0.


Log in to reply