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. QNetworkReply readall
Forum Updated to NodeBB v4.3 + New Features

QNetworkReply readall

Scheduled Pinned Locked Moved General and Desktop
9 Posts 6 Posters 6.7k Views 2 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.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    Hi, i see QNetworkReply can read content of website.

    Because my index.php contain about 5 numbers i try to use it.

    Code:
    @void download()
    {
    QUrl url("http://website.com/index.php");
    url.adQueryItem("version", 2); // = index.php?version=2

    QNetworkRequest netRequest(url);
    netReply = netManager.get(netRequest); // netReply = QNetworkReply, netManager = QNetworkAccessManager
    connect(netReply, SIGNAL(readyRead()), SLOT(read());
    }

    void read()
    {
    QString content = netReply->readAll();
    QMessageBox::information(0, "Info", content); // Web url content "987 654 321" But it show just "1"
    }@

    Any idea how to solve?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mETz
      wrote on last edited by
      #2

      QIODevice::readyRead() gets emitted whenever new/more data is available on the QIODevice, that is not necessarily all data. If you want to read all data in one go you rather want to connect to QNetworkReply::finished() but please bare in mind that all your data has to fit into memory for this to work.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #3

        Use "finished()":http://doc-snapshot.qt-project.org/4.8/qnetworkreply.html#finished SLOT instead of readyResd()

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          glararan
          wrote on last edited by
          #4

          change readyRead() to finished() but nothing changed

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #5

            Try this, and start you App from console or run directly from IDE with opened output window.
            If it doesn't help, and the SIZE != BODY length, check encoding, take wireschark and track back communication etc...

            @
            #include <QDebug>

            void read()
            {
            QString content = netReply->readAll();

            qDebug() << "SIZE: " << netReply->bytesAvailable();
            qDebug() << "BODY: " << QString(netReply->readAll());

            QMessageBox::information(0, "Info", content);
            }
            @

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • MecanikM Offline
              MecanikM Offline
              Mecanik
              wrote on last edited by
              #6

              I had the same issue. The QIODevice::readAll() (which is called from QNetworkReply) function states this issue:

              This function has no way of reporting errors; returning an empty QByteArray can mean either that no data was currently available for reading, or that an error occurred. This function also has no way of indicating that more data may have been available and couldn't be read.

              The resolution is to connect QIODevice::readyRead to as per the documentation:

              connect(reply, &QIODevice::readyRead, this, [=]() {
                  QByteArray response = reply->readAll();
                  qDebug() << response;
              });
              
              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #7

                10 years! This must surely be some new kind of record for the resurrection of a dead thread. :)

                JonBJ 1 Reply Last reply
                0
                • C ChrisW67

                  10 years! This must surely be some new kind of record for the resurrection of a dead thread. :)

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @ChrisW67
                  Not necessarily in the Qt world! I still find posts from 2011 a particularly good year :)

                  1 Reply Last reply
                  0
                  • MecanikM Offline
                    MecanikM Offline
                    Mecanik
                    wrote on last edited by
                    #9

                    @ChrisW67 said in QNetworkReply readall:

                    10 years! This must surely be some new kind of record for the resurrection of a dead thread. :)

                    Better later than never? ⊂(◉‿◉)つ

                    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