Results 1 to 18 of 18

Thread: Web services with Qt5 ??

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

    Default Web services with Qt5 ??

    Hi,

    I want some examples using web services with Qt5 , there is anyone can help me ?

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

    Default Re: Web services with Qt5 ??

    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 ??

    Hi,

    I didn't post the question until i passed two days searching on a topic treat web services with Qt5, so if you have something witch will help me i will apreciate it.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Web services with Qt5 ??

    The second link in that search has an introduction to that topic, including a full example in a github repository.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Web services with Qt5 ??

    Just in case Google gives you a different result set (because your search history is different):
    2. http://qmlbook.org/ch11/index.html
    4. http://ynonperek.com/course/qt/web-service.html

  6. #6
    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 ??

    Hi all,

    What realy i want is display weather informations on a Qt application using the web Service here http://www.webservicex.net/ws/WSDeta...TID=12&WSID=56 , but i don't realy know how to proceed

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Web services with Qt5 ??

    There are examples of such a request on the page you linked. You should probably use the POST method (last example) rather than a more involved SOAP request method. You can build the query string manually or using QUrlQuery (5.3) or QUrl (4.8). Build a QNetworkRequest pointing at the web service URL (you can find these in the WSDL linked from that page), set the Content-Type header as per the example, and call QNetworkManager:ost().

    This is a generic HTTP POST process and there are more than a few examples in these forums and the Qt Project forums.

  8. #8
    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 ??

    I started with this example, i want by this to display the link and number of views on youtube but i can't :

    testWebService.h
    Qt Code:
    1. #ifndef TESTWEBSERVICE_H
    2. #define TESTWEBSERVICE_H
    3.  
    4. #include <QtWidgets/QMainWindow>
    5. #include "ui_testwebservice.h"
    6. #include <QNetworkAccessManager>
    7. #include <QNetworkRequest>
    8. #include <QNetworkReply>
    9. #include <QScriptEngine>
    10. #include <QScriptValue>
    11. #include <QScriptValueIterator>
    12. #include <QUrl>
    13.  
    14. class TestWebService : public QMainWindow
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. TestWebService(QWidget *parent = 0);
    20. ~TestWebService();
    21.  
    22.  
    23. private slots:
    24. void onResult(QNetworkReply* reply);
    25.  
    26. private:
    27. Ui::TestWebServiceClass ui;
    28. QNetworkAccessManager m_networkManager;
    29. QNetworkReply* m_currentReply;
    30. };
    31.  
    32. #endif // TESTWEBSERVICE_H
    To copy to clipboard, switch view to plain text mode 


    testWebService.cpp
    Qt Code:
    1. #include "testwebservice.h"
    2.  
    3. TestWebService::TestWebService(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. ui.setupUi(this);
    7.  
    8. QUrl url("http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=json");
    9. QNetworkRequest request;
    10. request.setUrl(url);
    11. m_currentReply = NULL;
    12. m_currentReply = m_networkManager.get(request); // GET
    13.  
    14. connect(&m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onResult(QNetworkReply*)));
    15. }
    16.  
    17. TestWebService::~TestWebService()
    18. {
    19.  
    20. }
    21.  
    22. void TestWebService::onResult(QNetworkReply* reply)
    23. {
    24. if (m_currentReply->error() != QNetworkReply::NoError)
    25. return; // ...only in a blog post
    26.  
    27. QString data = (QString) reply->readAll();
    28.  
    29. QScriptEngine engine;
    30. QScriptValue result = engine.evaluate(data);
    31.  
    32.  
    33.  
    34. // Now parse this JSON according to your needs !
    35. QScriptValue entries = result.property("feed").property("entry");
    36. QScriptValueIterator it(entries);
    37. while (it.hasNext()) {
    38. it.next();
    39. QScriptValue entry = it.value();
    40.  
    41. QString link = entry.property("content").property("src").toString();
    42. int viewCount = entry.property("yt$statistics").property("viewCount").toInteger();
    43.  
    44. // Do something with those...
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 


    I don't get link and viewCount , does anyone know where is the problem in my code ?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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
    I don't get link and viewCount
    What do you get then?
    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.


  10. #10
    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 ??

    When debuging, i see that the "it" is empty the it doesn't enter in the while

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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
    When debuging, i see that the "it" is empty the it doesn't enter in the while
    What does "data" contain?
    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.


  12. #12
    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 ??

    Something like this

    Qt Code:
    1. {
    2. "version": "1.0",
    3. "encoding": "UTF-8",
    4. "feed": {
    5. ..
    6. ..
    7. "entry": [{
    8. "title": {
    9. "$t": "Nickelback- When We Stand Together"
    10. },
    11. "content": {
    12. "type": "application/x-shockwave-flash",
    13. "src": "http://www.youtube.com/v/76vdvdll0Y?version=3&f=standard&app=youtube_gdata"
    14. },
    15. "yt$statistics": {
    16. "favoriteCount": "29182",
    17. "viewCount": "41513706"
    18. },
    19. ...
    20. ...
    21. },
    22. ...
    23. ...
    24. ]
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Web services with Qt5 ??

    Any specific reason you are not using QJsonDocument for parsing JSON data?
    http://qt-project.org/doc/qt-5/qjsondocument.html

    Cheers,
    _

  14. #14
    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 ??

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


  16. #16
    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

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


  18. #18
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.