QNetworkReply readall



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



  • 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.



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



  • change readyRead() to finished() but nothing changed



  • 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);
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.