Results 1 to 6 of 6

Thread: WebService REST CPP-QML

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default WebService REST CPP-QML

    Hi Forum,

    I have a problem, I want to get the response from the serveur if the operation is Ok or not, So I analysed
    Qt Code:
    1. QNetworkRequest::HttpStatusCodeAttribute
    To copy to clipboard, switch view to plain text mode 

    // *** createProject( param ) ***
    Qt Code:
    1. //Create project using post json
    2. // ...
    3. reply = manager->post(request, dataByteArray);
    4. /* The finished() signal is triggered once an HTTP request is complete, by connect method we are connecting finished signal with the slot method onRequestFinished(user defined method). If it returns true it means connection is successful else not. You can process the response of the call in this user defined method */
    5. result = connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
    To copy to clipboard, switch view to plain text mode 

    // *** slot onFinished() ***
    Qt Code:
    1. bool Connection::onFinished()
    2. {
    3. codeResponse = false;
    4. qDebug() << "QNetworkRequest::HttpStatusCodeAttribute" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << "received";
    5.  
    6. if(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 201)
    7. {
    8. codeResponse = true;
    9. }
    10. return codeResponse;
    11. }
    To copy to clipboard, switch view to plain text mode 

    // *** getter ***
    Qt Code:
    1. bool Connection::getResponse()
    2. {
    3. return codeResponse;
    4. }
    To copy to clipboard, switch view to plain text mode 

    QML code
    Qt Code:
    1. connection.createProject( param );
    2. rep = connection.getResponse()
    3. console.log("Response: "+rep)
    4.  
    5. infoAdd.open()
    To copy to clipboard, switch view to plain text mode 

    All is OK, but in QML sometimes function getResponse() runs before the slot onFinished() ??

    So there is an other way whitout using getResponse() to get response from onFinichid() ?

    I tried to use connection.onFinichid() in QML but it executed 2 times :
    1st with connection.createProject( param ), 2nd directly connection.onFinichid() == > Response always = false

    I try to find an easy way to get the resp without getter getResponse()

    Cheers,
    Last edited by RegMe; 25th May 2016 at 11:43.

Similar Threads

  1. Redmine Rest API
    By Binary01 in forum Qt Programming
    Replies: 6
    Last Post: 24th May 2016, 11:00
  2. WebService
    By Binary01 in forum Qt Quick
    Replies: 1
    Last Post: 29th February 2016, 11:11
  3. Replies: 1
    Last Post: 15th June 2012, 12:45
  4. Webservice with QT
    By BP in forum Newbie
    Replies: 9
    Last Post: 16th June 2011, 05:08
  5. Using webservice in Qt
    By mind_freak in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2011, 06:50

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.