01-14-2013 08:04 PM - edited 01-14-2013 08:05 PM
I am trying to develop a simple image reader using the online service www.imgur.com. It's going to be free and ad-free which makes using the normal API easy enough. I have followed tutorials from the dev site to send a http request and to receive the reply. I have managed to do all that find but I am stumped with trying to apply the http reply to my ListView.
The reply is an XML file but with child-elements rather than attributes for information. I have been trying to get my reply working with the tutorial here:
specifically this part of code
// Create the data model using the contents of the file. The // location of the file is relative to the assets directory. XmlDataModel *dataModel = new XmlDataModel(); dataModel->setSource(QUrl("file://" + QDir::homePath() + "/model.xml")); // Set the new data model on the list and stop the activity indicator mListView->setDataModel(dataModel);
But I just can't get it to work. I have read from various people (but not confirmed on anything doc) that the XmlDataModel can't be used with child-element type XML files? If so, can anyone point me in the direction of converting to an attribute type XML file?
Solved! Go to Solution.
01-15-2013 04:01 AM
01-15-2013 07:44 AM - edited 01-15-2013 07:45 AM
Thanks for the replies! Using a DataSource object looks the easiest way to go about it, the only hesitation I have is that is that to access the api I need to put an identifying key in my request header. Currently it is done using
request.setRawHeader("Authorization", "Client-ID MY_CLIENT_ID");
Is there a way to do this using a DataSource object (or globally?)? The XML return from the server looks quite simple, I've attached a sample of it below to show the general structure:
<?xml version="1.0" encoding="utf-8"?> <data success="1" status="200"> <item> <id>Cot4g</id> <title>So someone posted a split pic earlier</title> <datetime>1358127556</datetime> <type>image/png</type> <animated>false</animated> <width>460</width> <height>611</height> <size>382970</size> <views>1059391</views> <bandwidth>405714971270</bandwidth> <vote/> <account_url/> <link>http://i.imgur.com/Cot4g.png</link> <ups>2479</ups> <downs>35</downs> <score>3305</score> <is_album>false</is_album> </item> <item> <id>Xz56B</id> <title>Shower this man n Karma</title> <datetime>1358133626</datetime> <type>image/jpeg</type> <animated>false</animated> <width>800</width> <height>595</height> <size>84355</size> <views>675548</views> <bandwidth>56985851540</bandwidth> <vote/> <account_url/> <link>http://i.imgur.com/Xz56B.jpg</link> <ups>2795</ups> <downs>111</downs> <score>3385</score> <is_album>false</is_album> </item> </data>
I've edited it to show the hierarchy of response. As you can see there is a root <data> element and then <item> elements which contain the various things I want to use. Is this simple enough for DataSource object to work?
Thanks for all your help!