I am working on a Sailfish OS app so I could use C++. For the moment it is working and my XML file will have not more than 100 entries. But I will look at QXmlStreamReader.
Are you familiar with Sailfish OS?
Thanks for the hint.
I am working on a Sailfish OS app so I could use C++. For the moment it is working and my XML file will have not more than 100 entries. But I will look at QXmlStreamReader.
Are you familiar with Sailfish OS?
Thanks for the hint.
Then the usual recommendation stands: don't use JavaScript for data processing that is not UI related.
Keep JS usage as minimal as possible.
So you need one value from each of these 100 entries?
And you are not needing these 100 values as a model?
- Extractnig values into a list or vector: QXmlStreamReader
- Needing the values only as a model in QML: XmlListModel
Haven't worked with it myself but I have heard about it.
It is the system used by Jolla, an embedded Linux using a Qt base application framework, with Wayland as the display technology.
Cheers,
_
The XML file contains dates and I want to display upcoming date on the first page. The JS is very fast I cannot see any delay but I will rework my xmlFileHandler class and add the option to extract the next event. Understand I correctly that you would put the XML file content into a QVector and than search through that?
By the way, I noticed a difference between JS and XmlListView. Within XmlListView my timestamps are not displayed correctly. I use the exact same code to convert the same timeStamp from the XML file. 6pm is displayed correctly but all other times are off a few seconds.
Is this a known issue?Qt Code:
Qt.formatDateTime(new Date(timeStamp,"dd.MM.yyyy - hh:mm" );To copy to clipboard, switch view to plain text mode
Avoiding JS it not only about performance, it is mostly about correctness and code maintainability.
Yes, if you extract a list of timestamps, I would store them in a vector or list of QDateTime.
The timeStamp value being the same in both cases?
Cheers,
_
Yes it is the same timestamp. I have the date in two locations. On the first page it is correct and on the full list page it is off.
How would you put the xml file into the vector? All code examples I have found look like this:
So if I go through the XML one by one I could also stop when I found what I was looking for without putting all elements into the vector.Qt Code:
while(!xml.atEnd() && !xml.hasError()) { /* Read next element.*/ QXmlStreamReader::TokenType token = xml.readNext(); /* If token is just StartDocument, we'll go to next.*/ if(token == QXmlStreamReader::StartDocument) continue; /* If token is StartElement, we'll see if we can read it.*/ if(token == QXmlStreamReader::StartElement) { if(xml.name() == "email") { ui->listWidget->addItem("Element: "+xml.name().toString()); continue; } } } /* Error handling. */ if(xml.hasError()) //resets its internal state to the initial state. xml.clear(); }To copy to clipboard, switch view to plain text mode
Not the XML file, the data you are interested in.
In the example that would be instead of line
Qt Code:
ui->listWidget->addItem("Element: "+xml.name().toString());To copy to clipboard, switch view to plain text mode
Of course.
That's one of the great things about QXmlStreamReader.
Cheers,
_
The formatDateTime() call you gives you a string representing the time stamp to an accuracy of minutes. How do you tell the value is "off a few seconds"?
For debugging I also displayed the seconds and saw that different timeStamps have different offsets. So 7pm is always off 16s 6pm is okay 19:30 is off 22s and so on.
Bookmarks