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. How to use QNetworkAccessManager post
Forum Updated to NodeBB v4.3 + New Features

How to use QNetworkAccessManager post

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 8.0k Views 1 Watching
  • 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
    SamFaye
    wrote on last edited by
    #4

    I do this @QUrl url; url.setUrl(valUrl);@

    An in my methode httpReadyRead I do this @if(!reply->readAll().isEmpty())
    {
    QFile compressedFile = new QFile("tempSAF");
    compressedFile->open(QIODevice::WriteOnly);
    compressedFile->write(reply->readAll());
    // char
    reponse = reply->readAll();
    qDebug() << "################# reply->readAll().size() = " << reply->readAll().size();
    // for(int i =0; i< sizeof(reponse);i++)
    // {
    // qDebug() << "################# reponse["<<i<<"] = " << reponse[i];
    // }
    //for(int)
    Etat = true;
    }
    else
    {
    qDebug() << "########### Impossible de réccupérer les données ";
    Etat=false;
    }@
    But this methode wase not executed. The reply is empty but the messe @qDebug() << "########### Impossible de réccupérer les données ";@ was not displayed.

    I have the same error

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SamFaye
      wrote on last edited by
      #5

      When I start debugging the value of url is: @synchronous data unavailable@ after the execution of this statement @reply =qnam.post(QNetworkRequest (url) m_pData);@

      m_pData has good values

      -NB-: I'm using https

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #6

        So, you meant that the other qDebug gets displayed?

        I'm not exactly sure, but I seem to vaguely remember, that after you do readAll(), QNR is flushed, so you can't really use it again. But I can't find any info on that in Qt 4.7 documentation, so my memory might be wrong here. Try storing the reply and doing the 'if' on the stored data.

        (Z(:^

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #7

          [quote author="SamFaye" date="1314711148"]I do this @QUrl url; url.setUrl(valUrl);@
          [/quote]

          That method has exactly the same problem as the constructor. Please use one of the static methods like QUrl::fromEncoded().

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SamFaye
            wrote on last edited by
            #8

            I have this error message when i use https and post @SSL: "Le nom d'hôte ne correspondait à aucun des hôtes valides pour ce certificat, Le certificat n'est pas sécurisé car auto-signé" @

            After this message my application crache

            My URL is like this: @https://Ip_machine/xxxxxxx@

            What is missing??

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #9

              You will have to handle SSL errors. See for example "this thread":http://developer.qt.nokia.com/forums/viewthread/5861/#35121.

              bq. Note that calling ["ignoreSslErrors()":http://doc.qt.nokia.com/latest/qnetworkreply.html#ignoreSslErrors] without restraint may pose a security risk for your application. Use it with care.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SamFaye
                wrote on last edited by
                #10

                I had done what Lukas Geyer said, now I didn't have the message but the application belong crashing

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #11

                  Where does it crash? Start the application in debug mode. The debugger will halt exactly where the application crashes.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SamFaye
                    wrote on last edited by
                    #12

                    This is because the other instructions are executed while the server response is not received. How to wait for the server response to continue execution of other instructions?

                    1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #13

                      For example, you can use:
                      @
                      forever {
                      if (replyReceived) {
                      processReply();
                      break;
                      }
                      else
                      qApp->processEvents();
                      }
                      @
                      This will not block your app. Substitute if condition and processing with your own.

                      (Z(:^

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        lgeyer
                        wrote on last edited by
                        #14

                        [quote author="SamFaye" date="1314899811"]This is because the other instructions are executed while the server response is not received. How to wait for the server response to continue execution of other instructions?[/quote]

                        Which other instructions? QNAM emits the finished signal when the response is available. This is where your response handling code has to go.

                        Blocking your application until data is available is usually not the solution, it just covers a severe design flaw.

                        1 Reply Last reply
                        0

                        • Login

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