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…
1. 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.
2. 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.
3. 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.0
Rectangle {
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 }
}
}
}
}
}
↧