开发者

Problems loading a webpage into QML XmlListModel

开发者 https://www.devze.com 2023-03-09 23:56 出处:网络
import QtQuick 1.0 Rectangle { Component { id: delegate Text{text: title} } ListView { y:10 id: view anchors.fill: parent
import QtQuick 1.0

Rectangle {
  Component {
    id: delegate
        Text{text: title}
  }

  ListView {
    y:10
    id: view
    anchors.fill: parent
    model: model
    delegate: delegate
  }


  XmlListModel {
    id:model
    source: "http://www.w3.org/"
    query: "/html/head"
    namespaceDeclarati开发者_如何学Goons: "declare default element namespace 'www.w3.org/1999/xhtml/';"

    XmlRole { name: "title"; query: "title/string()" }
  }
}

I would expect that my model would now contain one Element with title="World Wide Web Consortium (W3C)" but nothing is displayed. model.count is zero, but model.progress is 1 Am I using the wrong namespace declarations?

many thanks

Patrick


Try this:

XmlRole { name: "title"; query: "title[1]/string()" }

Putting a 1 in the array, indicate that you want to retrieve the first title.


The namespace needs to be the exact namespace declared in the document. Instead of "www.w3.org/1999/xhtml", the declared namespace should be "http://www.w3.org/1999/xhtml".

0

精彩评论

暂无评论...
验证码 换一张
取 消