Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting the HTTP standard response code from a QNetworkReply

Getting the HTTP standard response code from a QNetworkReply

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 29.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    scarleton
    wrote on 10 Aug 2011, 04:19 last edited by
    #1

    I am working on some code to get an image from a web server using QNetworkReply. Since there is security to be concerned with, I need to look at the HTTP standard response code to determine if the result is a clean 200 or some type of error. How exactly do I get the the HTTP standard response code?

    1 Reply Last reply
    1
    • D Offline
      D Offline
      DenisKormalev
      wrote on 10 Aug 2011, 07:41 last edited by
      #2

      Have you tried "error()":http://doc.qt.nokia.com/4.7/qnetworkreply.html#error method?

      1 Reply Last reply
      1
      • D Offline
        D Offline
        dangelog
        wrote on 10 Aug 2011, 08:01 last edited by
        #3

        The raw response code is available as an integer using the QNetworkReply::attribute(QNetworkRequest::HttpStatusCodeAttribute) method.

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        2
        • Z Offline
          Z Offline
          ZapB
          wrote on 10 Aug 2011, 09:52 last edited by
          #4

          Connect a slot up to the QNetworkReply::metaDataChanged() signal. Then in that slot you can check what you need:

          @
          QVariant statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
          if ( !statusCode.isValid() )
          return;

          int status = statusCode.toInt();
          
          if ( status != 200 )
          {
              QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
              qDebug() << reason;
          }
          

          @

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          2

          1/4

          10 Aug 2011, 04:19

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved