Solved How use XmlListModel ?
-
Hi!
How use XmlListModel ?
I tried to load XML as an example, but got nothing. -
-
@mikeeeeee I really hope one day you will learn how to ask a question...
-
How can I use thes XML:
This my code:
import QtQuick 2.12
import QtQuick.XmlListModel 2.12
import QtQuick.Controls 2.12Item {
width: 400
height: 700XmlListModel { id: xmlModel source: appCore.testXml()//"http://www.mysite.com/feed.xml" //query: "/rss/channel/item" // XmlRole { name: "title"; query: "title/string()" } // XmlRole { name: "pubDate"; query: "pubDate/string()" } }
}
appCore.testXml() return:
<hottours>
<hotcount>16</hotcount>
<tour>
<tourid>1568434258192</tourid>
<countrycode>4</countrycode>
<countryname>Турция</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>15</operatorcode>
<operatorname>TezTour</operatorname>
<hotelcode>60203</hotelcode>
<hotelname>CLUB SUNNY WORLD (EX.ORIENT HILL RESORT HOTEL)</hotelname>
<hotelstars>5</hotelstars>
<hotelregioncode>19</hotelregioncode>
<hotelregionname>Алания</hotelregionname>
<hotelrating>3.76</hotelrating>
<fulldesclink>
http://manyhotels.ru/#!/hotel=orient-hill-resort-hotel
</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/60203.jpg</hotelpicture>
<flydate>19.07.2019</flydate>
<nights>6</nights>
<meal>AI</meal>
<price>26389</price>
<priceold>38551</priceold>
<fuelcharge>2524</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>1568474811541</tourid>
<countrycode>20</countrycode>
<countryname>Болгария</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>15</operatorcode>
<operatorname>TezTour</operatorname>
<hotelcode>6942</hotelcode>
<hotelname>DOUBLETREE BY HILTON</hotelname>
<hotelstars>5</hotelstars>
<hotelregioncode>130</hotelregioncode>
<hotelregionname>Золотые Пески</hotelregionname>
<hotelrating>4.06</hotelrating>
<fulldesclink>
http://manyhotels.ru/#!/hotel=doubletree-by-hilton2
</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/6942.jpg</hotelpicture>
<flydate>24.07.2019</flydate>
<nights>9</nights>
<meal>UAI</meal>
<price>33635</price>
<priceold>48610</priceold>
<fuelcharge>1442</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>1565735949946</tourid>
<countrycode>6</countrycode>
<countryname>Греция</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>15</operatorcode>
<operatorname>TezTour</operatorname>
<hotelcode>47736</hotelcode>
<hotelname>POSEIDON PALACE</hotelname>
<hotelstars>5</hotelstars>
<hotelregioncode>82</hotelregioncode>
<hotelregionname>Пелопоннес</hotelregionname>
<hotelrating>4.47</hotelrating>
<fulldesclink>http://manyhotels.ru/#!/hotel=poseidon-palace191</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/47736.jpg</hotelpicture>
<flydate>28.07.2019</flydate>
<nights>6</nights>
<meal>HB</meal>
<price>28263</price>
<priceold>40763</priceold>
<fuelcharge>0</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>4367055755216</tourid>
<countrycode>47</countrycode>
<countryname>Россия</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>43</operatorcode>
<operatorname>Интурист</operatorname>
<hotelcode>65947</hotelcode>
<hotelname>ВЕЛОХОСТЕЛ МАРАТА</hotelname>
<hotelstars>4</hotelstars>
<hotelregioncode>470</hotelregioncode>
<hotelregionname>Санкт-Петербург</hotelregionname>
<hotelrating>4</hotelrating>
<fulldesclink>http://manyhotels.ru/#!/hotel=velohostel-marata</fulldesclink>
<hotelpicture>
//static.tourvisor.ru/hotel_pics/small/hotel_country_47.jpg
</hotelpicture>
<flydate>27.07.2019</flydate>
<nights>6</nights>
<meal>RO</meal>
<price>10426</price>
<priceold>12642</priceold>
<fuelcharge>0</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>4366956656535</tourid>
<countrycode>5</countrycode>
<countryname>Тунис</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>43</operatorcode>
<operatorname>Интурист</operatorname>
<hotelcode>1760</hotelcode>
<hotelname>IBEROSTAR SAPHIR PALACE</hotelname>
<hotelstars>5</hotelstars>
<hotelregioncode>31</hotelregioncode>
<hotelregionname>Хаммамет</hotelregionname>
<hotelrating>4.24</hotelrating>
<fulldesclink>
http://manyhotels.ru/#!/hotel=iberostar-saphir-palace
</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/1760.jpg</hotelpicture>
<flydate>19.07.2019</flydate>
<nights>6</nights>
<meal>AI</meal>
<price>32860</price>
<priceold>37797</priceold>
<fuelcharge>0</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>1567850724466</tourid>
<countrycode>19</countrycode>
<countryname>Чехия</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>15</operatorcode>
<operatorname>TezTour</operatorname>
<hotelcode>43276</hotelcode>
<hotelname>GOLF DEPANDANCE</hotelname>
<hotelstars>4</hotelstars>
<hotelregioncode>120</hotelregioncode>
<hotelregionname>Прага</hotelregionname>
<hotelrating>4.78</hotelrating>
<fulldesclink>http://manyhotels.ru/#!/hotel=golf-depandance</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/43276.jpg</hotelpicture>
<flydate>01.08.2019</flydate>
<nights>6</nights>
<meal>BB</meal>
<price>26389</price>
<priceold>37112</priceold>
<fuelcharge>0</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>1568263451062</tourid>
<countrycode>57</countrycode>
<countryname>Беларусь</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>15</operatorcode>
<operatorname>TezTour</operatorname>
<hotelcode>40683</hotelcode>
<hotelname>ВОЯЖ</hotelname>
<hotelstars>3</hotelstars>
<hotelregioncode>493</hotelregioncode>
<hotelregionname>Минская обл.</hotelregionname>
<hotelrating>4.61</hotelrating>
<fulldesclink>http://manyhotels.ru/#!/hotel=voyaj196</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/40683.jpg</hotelpicture>
<flydate>22.07.2019</flydate>
<nights>6</nights>
<meal>RO</meal>
<price>15961</price>
<priceold>20986</priceold>
<fuelcharge>0</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>1269656539310</tourid>
<countrycode>55</countrycode>
<countryname>Азербайджан</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>12</operatorcode>
<operatorname>Pegas</operatorname>
<hotelcode>41602</hotelcode>
<hotelname>PREMIER</hotelname>
<hotelstars>4</hotelstars>
<hotelregioncode>482</hotelregioncode>
<hotelregionname>Баку</hotelregionname>
<hotelrating>5</hotelrating>
<fulldesclink>http://manyhotels.ru/#!/hotel=premier</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/41602.jpg</hotelpicture>
<flydate>01.08.2019</flydate>
<nights>6</nights>
<meal>BB</meal>
<price>27460</price>
<priceold>40642</priceold>
<fuelcharge>0</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>4368887594807</tourid>
<countrycode>31</countrycode>
<countryname>Австрия</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>43</operatorcode>
<operatorname>Интурист</operatorname>
<hotelcode>23370</hotelcode>
<hotelname>BEST WESTERN PLUS AMEDIA</hotelname>
<hotelstars>4</hotelstars>
<hotelregioncode>204</hotelregioncode>
<hotelregionname>Вена</hotelregionname>
<hotelrating>4.89</hotelrating>
<fulldesclink>http://manyhotels.ru/#!/hotel=amedia-vienna</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/23370.jpg</hotelpicture>
<flydate>27.07.2019</flydate>
<nights>6</nights>
<meal>BB</meal>
<price>33180</price>
<priceold>39047</priceold>
<fuelcharge>0</fuelcharge>
<currency>RUB</currency>
</tour>
<tour>
<tourid>1563668757635</tourid>
<countrycode>24</countrycode>
<countryname>Италия</countryname>
<departurecode>1</departurecode>
<departurename>Москва</departurename>
<departurenamefrom>Москвы</departurenamefrom>
<operatorcode>15</operatorcode>
<operatorname>TezTour</operatorname>
<hotelcode>61262</hotelcode>
<hotelname>SAN DOMENICO SOVERATO</hotelname>
<hotelstars>3</hotelstars>
<hotelregioncode>163</hotelregioncode>
<hotelregionname>Калабрия</hotelregionname>
<hotelrating>5</hotelrating>
<fulldesclink>
http://manyhotels.ru/#!/hotel=san-domenico-soverato
</fulldesclink>
<hotelpicture>//static.tourvisor.ru/hotel_pics/small/61262.jpg</hotelpicture>
<flydate>29.07.2019</flydate>
<nights>7</nights>
<meal>BB</meal>
<price>29092</price>
<priceold>42626</priceold>
<fuelcharge>0</fuelcharge>
<currency>RUB</currency>
</tour>
</hottours> -
@mikeeeeee said in How use XmlListModel ?:
How can I use thes XML
as you wish, i still don't know what you are trying to achieve.
you can construct tour objects from it, just try to understand the example i gave you before. -
I need to load this XML onto the interface. Looking at the example I did not understand how to do it.
-
@mikeeeeee Did you read the documentation?
It explains how to do it: https://doc.qt.io/qt-5/qml-qtquick-xmllistmodel-xmllistmodel.html
You will even find a link to an example there: https://doc.qt.io/qt-5/qtdoc-demos-rssnews-example.html -
I read, I assume you did, too. Based on this example, it is not clear what to do in my case. Surely I need to correct 1-2 lines. Do you know how to do this?
-
@mikeeeeee Please tell us what EXACTLY is not working?
You have your XML model. Where do you want to show it?
You have to show it in a view like shown in the documentation:ListView { width: 180; height: 300 model: xmlModel delegate: Text { text: title + ": " + pubDate } }
-
I append ListView , but it's not work
import QtQuick 2.12
import QtQuick.XmlListModel 2.12
import QtQuick.Controls 2.12Item {
width: 400
height: 700XmlListModel { id: xmlModel source: appCore.testXml()//"http://www.mysite.com/feed.xml" //query: "/rss/channel/item" // XmlRole { name: "title"; query: "title/string()" } // XmlRole { name: "pubDate"; query: "pubDate/string()" } } ListView { id: testListView anchors.fill: parent model: xmlModel delegate: Text { text: "testListView: " } }
}
-
It's work
XmlListModel { id: xmlModel xml: appCore.testXml() query: "/hottours/tour" //query: "/tour" // XmlRole { name: "title"; query: "title/number()" } XmlRole { name: "tastText"; query: "hotelcode/string()" } } ListView { id: testListView anchors.fill: parent model: xmlModel delegate: Text { text: tastText } }