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.XmlListModel
XmlListModel은 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 값은 XML 문서에서 각 <item> 에 대한 모델 항목을 생성하도록 XmlListModel이 지정합니다.
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 데이터를 읽고 모델에 로드된 시기는 상태 속성을 사용하여 확인할 수 있습니다.
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.오류인 경우 마지막으로 발생한 오류에 대한 문자열 설명을 반환합니다.
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.