Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Thumbnails in rss
I am trying to parse an rss xml. I am new to parsing and new to Qt, so bear with me.
In my rss feed i have a tag like this
<media:thumbnail url="http://*..///GetImage.aspx?id=1555B71D7BEA3AAB" />
My question is how do i parse it. I mean against what tag. Secondly when I do parse it what do I get. Do i just get the url? Do i get the Image? Thirdly if I want to display this thumbnail, how do i do that. Is there any way to display an image direct from a url in Qt? specially inside a QTreeWidget. Finally, how do i download the image and resize it to be displayed if i cannot display it directly from the url?
I know these are a lot of questions but I am new and kind of feel like I am running around in circles, chasing my tail. Your patience in answering all of these will be much appreciated.
[EDIT: code formatting for XML snippet, Volker]
andre last edited by
rss is an XML format, so I would suggest you use the XML functionality in Qt to do the parsing for you instead. That will be way less error-phrone and much easier. Might I suggest QXmlStreamReader for the job?
What you have in the tag you display is a URL. That is: a web address. You will need to use a class like QNetworkAccessManager to retreive the contents. There is a way to do it directly, but only in QML. It would be nice if the functionality to load images directly from a URL was somehow exposed on the C++ side as well, but it is not at this moment.
Once you have the image inside a QImage, you can use that class to do the resizing for you. To put it in a QTreeWidget, you simply set the QImage as data on the appropriate item using the Qt::DecorationRole.
You are right that you're asking a lot of questions at once. Perhaps you should first try your hand with some of the Qt tutorials. I have given you some pointers, but the idea is not that people here will write the code for you. You're expected to do your own research too.
Thank you for all the pointers. I have been going through the tutorials and everything and they are wonderful.
But i think I didn't make my problem clear. I am using the parser in Qt. My problem is that I have not yet found a way to parse the tag that i have given above.
Let me make it clear with an example.
<name> blah blah blah </name>
this line is easily handled by my parser but
<media:thumbnail url = "....." />
what tag do i search this against? My parser doesn't even read it. The last tag it reads is "guid" then it moves on to the next item. I should mention that the rss feed i am trying to parse is a media rss.
[quote author="awasay" date="1297937083"]
<media:thumbnail url = "....." />
what tag do i search this against? My parser doesn't even read it. The last tag it reads is "guid" then it moves on to the next item. I should mention that the rss feed i am trying to parse is a media rss. [/quote]
This is a tag with namespace prepended. You will have to consider this. The local tag name without namespace should be "thumbnail".
Thank you. i can now get into the thumbnail tag. A new problem has arisen though. My parser is not dealing with the empty spaces. How do i make it either skip the empty space or get the line with the empty space.
In my research so far, all skip functions skip the whole element.
Whatever "empty spaces" are...
Once again i thank you for your patience. I am using the QXmlStreamReader. In fact most of my code is copied from the help section. The problem is that it is not dealing with a tag of the type mentioned above. "empty space" is where there is nothing.
when i find the tag "thumbnail", i call the function
myString = xml.text().toString();
when I display myString through QDebug, it is shown empty. my theory is that it is being displayed empty because the parser is not dealing with the tag properly.
P.S. I am able to get the simple tags displayed properly.
You should learn the difference between tag, tag content and attribute. I'd suggest an introduction or tutorial to XML to make yourself comfortable with the XML concepts.
thank you once again. like i mentioned in the beginning, i am new to all of this. today has been a steep learning curve helped by all of you. incidentally, i just figured out (before reading your post) that the text function would return empty, i need to somehow access the attributes of "media". now i am off to find how to access attributes. if anyone of you is feeling in a giving mood then feel free to point me in the right direction.
P.S. I know handing stuff out on a plate is frowned upon in the forums and I agree with it most of the times but i feel that sometimes quick answers do lead to quick learning as well.
My two cents,
Is it really so hard to go to http://doc.qt.nokia.com/4.7/qxmlstreamreader.html, hit Ctrl-F, enter "attribute" click some times on "search more" and eventually find yourself at the right place.
You are just stinking lazy if you expect others to do the actual work for you! You are very welcome to ask questions if you have a real problem and a real question. But everyone is upset if you just steal their times when on the answer is crystal clear in the docs!
i do not wish to make you angry, i apologize for my behavior. I did not say that I was not going to look. In fact I am reading the docs that you have mentioned at the moment(without using your provided links). My point was that "sometimes", if you have gone through a similar problem yourself, you can give the solution.
I apologize once again.
This is true, but only for "serious" problems, not for questions that are easily answered in the API docs. Some work an research should always be done, before asking in a forum.
So, have fun reading the Qt docs (the are really good!) :-)
Hey thanx once again for bearing with me. I have figured out some part of the attributes problem. Its still not as clear as I would like it to be but at least its working. I am sure the clarity will come with time.