From 457dc2c47bd77ecb11b67538c5fbff8e54a386b3 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 5 May 2023 18:24:29 +0200 Subject: [PATCH] rsslisting example: fix bug in construction of title string The correct time to clear titleString and linkString is at the start of the item element, to avoid not only the left-overs from a previous item but also any stray titles and links that don't belong to any item. The channel element, that contains the items, may also have title and link elements. This, indeed, lead to the first entry in the displayed table having a "Qt Blog" prefix on its blog-post's title. Fortunately the link was already being set, usually to empty, due to the lack of rss:about attributes on item elements. Task-number: QTBUG-111228 Change-Id: I16647e2498b58caaafa6e88ef73f0d934a1f8396 Reviewed-by: Alex Blasche Reviewed-by: Ivan Solovev (cherry picked from commit 637e1542cfd75969edabba547af693f29411e6aa) Reviewed-by: Qt Cherry-pick Bot --- examples/corelib/serialization/rsslisting/rsslisting.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/corelib/serialization/rsslisting/rsslisting.cpp b/examples/corelib/serialization/rsslisting/rsslisting.cpp index 7ce35c9f2a3..f3317fd2bf7 100644 --- a/examples/corelib/serialization/rsslisting/rsslisting.cpp +++ b/examples/corelib/serialization/rsslisting/rsslisting.cpp @@ -163,8 +163,10 @@ void RSSListing::parseXml() while (!xml.atEnd()) { xml.readNext(); if (xml.isStartElement()) { - if (xml.name() == u"item") + if (xml.name() == u"item") { linkString = xml.attributes().value("rss:about").toString(); + titleString.clear(); + } currentTag = xml.name().toString(); } else if (xml.isEndElement()) { if (xml.name() == u"item") { @@ -173,9 +175,6 @@ void RSSListing::parseXml() item->setText(0, titleString); item->setText(1, linkString); treeWidget->addTopLevelItem(item); - - titleString.clear(); - linkString.clear(); } } else if (xml.isCharacters() && !xml.isWhitespace()) {