Results 1 to 18 of 18

Thread: Web services with Qt5 ??

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Web services with Qt5 ??

    No there is no specific reason, i just didn't know it, i tried parsing JSON data with QJsonDocument but it doesn't work
    Qt Code:
    1. QStringList propertyLinks;
    2. QStringList propertyViews;
    3. if (m_currentReply->error() != QNetworkReply::NoError)
    4. return; // ...only in a blog post
    5.  
    6. QString data = (QString) reply->readAll();
    7.  
    8. QJsonDocument jsonResponse = QJsonDocument::fromJson(data.toUtf8());
    9. QJsonObject jsonObject = jsonResponse.object();
    10.  
    11. QJsonArray jsonArrayContents = jsonObject["content"].toArray();
    12. QJsonArray jsonArrayStatistics= jsonObject["yt$statistics"].toArray();
    13.  
    14. foreach (const QJsonValue & value, jsonArrayContents)
    15. {
    16. QJsonObject obj = value.toObject();
    17. propertyLinks.append(obj["src"].toString());
    18. }
    19.  
    20. foreach (const QJsonValue & value, jsonArrayStatistics)
    21. {
    22. QJsonObject obj = value.toObject();
    23. propertyViews.append(obj["viewCount"].toString());
    24. }
    To copy to clipboard, switch view to plain text mode 

    any problem with my code ??

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Web services with Qt5 ??

    Quote Originally Posted by hassinoss View Post
    but it doesn't work
    Please, never say something "doesn't work" without specifying the details. Such information is really useless.

    any problem with my code ??
    Yes

    Even at first glance I can see that in line #6 you are casting a QByteArray to QString only to transform it back (using toUtf8() this time) in line #8.

    As for real problems, in line #11 you ask for the object's "content" property while it doesn't have such property. "content" is a property of "entry" which itself is a property of "feed". It is all quite obvious once you look at both your code and your input data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Web services with Qt5 ??

    Thanx for your reply,
    I realy don't know how to parse a json file, also i'm newbie in javascript, so can you give me the code how to get the src and viewCount from the file

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Web services with Qt5 ??

    Quote Originally Posted by hassinoss View Post
    Thanx for your reply,
    I realy don't know how to parse a json file, also i'm newbie in javascript, so can you give me the code how to get the src and viewCount from the file
    Oh come on. Did you understand my previous post? This has nothing to do with "knowing how to parse a json file", that's what you have QJsonDocument for.
    Last edited by wysota; 24th August 2014 at 07:59.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Web services with Qt5 ??

    Sorry , now i know what did you mean, thanx

Similar Threads

  1. Web services in qt ???
    By sai_3289 in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2012, 08:24
  2. Better way of using the services of QWSServer
    By Ratheendrans in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 13th July 2012, 05:44
  3. Where can I find web services api that Qt can use ?
    By kellen851105 in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2010, 06:25
  4. QT for background-services
    By invictus in forum Newbie
    Replies: 3
    Last Post: 23rd March 2007, 09:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.