XmlListModel QML Type
XML 데이터를 사용하여 읽기 전용 모델을 지정하기 위한 것입니다. 더 보기...
| Import Statement: | import QtQml.XmlListModel |
속성
- count : int
- progress : real
- query : string
- roles : list<XmlListModelRole>
- source : url
- status : enumeration
방법
- string errorString()
- void reload()
상세 설명
이 요소를 사용하려면 다음 코드를 사용하여 모듈을 임포트해야 합니다:
import QtQml.XmlListModelXmlListModel은 XML 데이터로부터 읽기 전용 모델을 생성하는 데 사용됩니다. 이 모델은 뷰 요소(ListView, PathView, GridView 등) 및 모델 데이터와 상호작용하는 기타 요소(Repeater 등)의 데이터 소스로 사용할 수 있습니다.
참고: 이 모델은 XPath 쿼리를 지원하지 않습니다. 슬래시로 구분된 간단한 경로와, 선택적으로 각 요소당 하나의 속성을 지원합니다.
예를 들어, https://www.qt.io/blog/rss.xml에 다음과 같은 XML 문서가 있다고 가정해 봅시다:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
...
<channel>
<item>
<title>Qt 6.0.2 Released</title>
<link>https://www.qt.io/blog/qt-6.0.2-released</link>
<pubDate>Wed, 03 Mar 2021 12:40:43 GMT</pubDate>
</item>
<item>
<title>Qt 6.1 Beta Released</title>
<link>https://www.qt.io/blog/qt-6.1-beta-released</link>
<pubDate>Tue, 02 Mar 2021 13:05:47 GMT</pubDate>
</item>
<item>
<title>Qt Creator 4.14.1 released</title>
<link>https://www.qt.io/blog/qt-creator-4.14.1-released</link>
<pubDate>Wed, 24 Feb 2021 13:53:21 GMT</pubDate>
</item>
</channel>
</rss>XmlListModel은 이 데이터를 사용하여 다음과 같이 모델을 생성할 수 있습니다.
import QtQml.XmlListModel
XmlListModel {
id: xmlModel
source: "https://www.qt.io/blog/rss.xml"
query: "/rss/channel/item"
XmlListModelRole { name: "title"; elementName: "title" }
XmlListModelRole { name: "pubDate"; elementName: "pubDate" }
XmlListModelRole { name: "link"; elementName: "link" }
}"/rss/channel/item"의 query 값은 XmlListModel이 XML 문서 내의 각 <item> 에 대해 모델 항목을 생성해야 함을 지정합니다.
XmlListModelRole 객체는 모델 항목의 속성을 정의합니다. 여기서 각 모델 항목은 해당 <item> 의 title, pubDate 및 link 값과 일치하는 title, pubDate 및 link 속성을 갖게 됩니다. (더 많은 예제는 XmlListModelRole 문서를 참조하십시오.)
이 모델은 다음과 같이 ListView에서 사용할 수 있습니다:
ListView {
width: 180; height: 300
model: xmlModel
delegate: Text { text: title + ": " + pubDate + "; link: " + link }
}XmlListModel 데이터는 비동기적으로 로드되며, 로드가 완료되면 status 가 XmlListModel.Ready 로 설정됩니다. 즉, 뷰에 XmlListModel 가 사용될 경우 모델이 로드될 때까지 뷰에 데이터가 채워지지 않는다는 점에 유의하십시오.
속성 문서
count : int
모델에 포함된 데이터 항목의 수.
progress : real
이는 XML 데이터 소스의 다운로드 진행 상황을 나타냅니다. 이 값의 범위는 0.0(데이터 미다운로드)부터 1.0(모든 데이터 다운로드 완료)까지입니다. XML 데이터가 원격 소스에서 가져온 것이 아닌 경우, 데이터가 읽히자마자 진행 상황이 1.0이 됩니다.
진행 상황이 1.0일 때는 XML 데이터가 다운로드되었지만, 아직 모델에 로드되지는 않은 상태임을 유의하십시오. XML 데이터가 읽혀서 모델에 로드된 시점을 확인하려면 status 속성을 사용하십시오.
query : string
이 모델의 ` XmlListModelRole ` 객체에서 모델 항목을 생성할 때 사용되는 기본 경로를 나타내는 문자열입니다. 쿼리는 '/' 로 시작해야 합니다.
roles : list<XmlListModelRole>
이 모델에 사용할 수 있도록 설정할 역할들.
source : url
XML 데이터 소스의 위치.
status : enumeration
모델 로딩 상태를 지정하며, 다음 중 하나를 선택할 수 있습니다:
| 상수 | 설명 |
|---|---|
XmlListModel.Null | 이 모델에 대해 XML 데이터가 설정되어 있지 않습니다. |
XmlListModel.Ready | XML 데이터가 모델에 로드되었습니다. |
XmlListModel.Loading | 모델이 XML 데이터를 읽고 로드하는 중입니다. |
XmlListModel.Error | 모델을 로드하는 동안 오류가 발생했습니다. 오류에 대한 자세한 내용은 errorString()을 참조하십시오. |
progress도 참조하십시오 .
메서드 문서
string errorString()
status 가 XmlListModel.Error인 경우, 마지막으로 발생한 오류에 대한 설명 문자열을 반환합니다.
void reload()
모델을 다시 불러옵니다.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.