RSS Feed Display - not quite right!!
-
Hi All,
Can anyone help me tidy the code below, basically it pulls an RSS feed from the BBC and displays it in a list view. However there are a few issues that I cannot get my head around...
-
The timer doesnt seem to work, though if called from another QML file it does?? Basically this is for a signage solution so I dont want to advance the list through intraction but purely based on a interval.
-
When the timer is working the articles scroll through as they should, but then when it reaches the last article the list animates backwards until it reaches the start, this doesnt look very good. I was hoping to hide it or reload it or something similar once it reached the end but I am struggling to make it work at the moment.
-
How can I reload the XML feed say every hour? I have started to research loading and unloading a QML file from within a QML file but in my head that seems messy and I am sure there is a tidier way?
Many thanks.
@import QtQuick 2.0
import QtQuick.XmlListModel 2.0Rectangle {
id: screen x: 1345 y: 543 width: 545 height: 150
property int currentIndex: 1
Timer {
interval: 5000; running: true;repeat: true
onTriggered:advanceIndex()
}property int currentindexPos: 0
function advanceIndex()
{
//list.positionViewAtIndex(currentindexPos,ListView.Center)
list.currentIndex = currentindexPos
currentindexPos = currentindexPos + 1
if(currentindexPos >= list.count)
descriptionText.visible = "false";
currentindexPos = 0}
XmlListModel { id: feedModel source: "http://feeds.bbci.co.uk/news/uk/rss.xml" query: "/rss/channel/item" XmlRole { name: "title"; query: "title/string()" } XmlRole { name: "pubDate"; query: "pubDate/string()" } XmlRole { name: "description"; query: "description/string()" } } ListView { clip: true id:list width: 545; height: 150 model: feedModel focus: true Keys.onLeftPressed: { if (currentIndex > 0 ) currentIndex = currentIndex-1;} Keys.onRightPressed: { if (currentIndex < count) currentIndex = currentIndex+1;} delegate: rssDisplay } Component { id: rssDisplay Item { width: 500; height: 300 Column { x: 10 y: 10 Text { id: titleText text: title width: 500 wrapMode: Text.WordWrap color: "red" font { bold: true; family: "Helvetica"; pointSize: 16 } } Text { id: descriptionText text: description width: 500 wrapMode: Text.WordWrap font { bold: true; family: "Helvetica"; pointSize: 16 } } } } }
}
@ -
-
Hi, is there a reason you came up with your own property and function for the current index? The ListView already has a property currentIndex and also a function incrementCurrentIndex(), maybe you missed it check the doc it might help you. :)
About the timer I have no idea it should work like that, try and add some log messages if it really is the timer or the function it calls that doesn't work.
- I never used the XmlListModel but to reload the data you might just reset the model (set the source to "undefined" and than the URL string again), you have to unset it or it won't trigger a change event so just remove the model first. :D
There might be a cleaner way but this isn't so bad I think.
Edit: I just checked the doc, XmlListModel has a reload function what about that? :)
- I never used the XmlListModel but to reload the data you might just reset the model (set the source to "undefined" and than the URL string again), you have to unset it or it won't trigger a change event so just remove the model first. :D