[Qt-interest] QT 4.6: Strange behavior while using QNAM for multiple HTTP requests

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Mon May 3 07:51:38 CEST 2010


This email contained a .zip file attachment. Raytheon does not allow email attachments that are considered likely to contain malicious code. For your protection this attachment has been removed.

If this email is from an unknown source, please simply delete this email.

If this email was expected, and it is from a known sender, you may follow the below suggested instructions to obtain these types of attachments.

+ Instruct the sender to enclose the file(s) in a ".zip" compressed file, and rename the ".zip" compressed file with a different extension, such as, ".rtnzip".  Password protecting the renamed ".zip" compressed file adds an additional layer of protection. When you receive the file, please rename it with the extension ".zip".

Additional instructions and options on how to receive these attachments can be found at:

http://security.it.ray.com/antivirus/extensions.html
http://security.it.ray.com/news/2007/zipfiles.html

Should you have any questions or difficulty with these instructions, please contact the Help Desk at 877.844.4712

---

Hi All,

I'm experiencing some strange behavior while using
QNetworkAccessManager (QNAM) for fetching data from multiple URL's in
a loop. The finished signal of QNAM is emitted TWICE for each URL,
once with full data and next with 0 bytes. I'm not sure if my usage is
correct or not.

Here's the code snippet which actually starts the download in a loop.
I have placed 2 files, test1.jpg and test2.jpg in webserver's (nginx)
root.

<snip>
void download() {
    for (int i=1; i<3; i++) {
        QString urlStr = QString("http://localhost/test%1.jpg").arg(i);
        qDebug() << urlStr;

        QNetworkRequest req;
        req.setUrl(QUrl(urlStr));
        qDebug() << "Pipelining allowed -"
                 <<
req.attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool();

        mgr->get(req);
        connect(mgr, SIGNAL(finished(QNetworkReply*)),
                this, SLOT(getData(QNetworkReply*)));
    }
}

void getData(QNetworkReply* reply) {
    qDebug() << "Reply for req" << reply->request().url();
    qDebug() << "Status code"
             <<
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

    if (reply->error() != QNetworkReply::NoError) {
        qDebug() << "Error fetching data from" << reply->url();
        return;
    }

    qDebug() << "Bytes available" << reply->bytesAvailable();

    QByteArray bytes = reply->readAll();
    qDebug() << "Rx'ed" << bytes.size();
    reply->deleteLater();
}
</snip>

On the webserver I see only 2 requests landing, i.e for test1.jpg and
test2.jpg. However, the getData() slot is getting called twice!
readAll() is getting me the complete file the first time and in the
next callback it's 0.

Also, if I run the loop only once (i.e put only a single req for say
test1.jpg, then the getData slot gets called only once!).

The status code returned is 200 always.

Also, the request object is showing that the HTTP Pipelining is NOT
supported by QNAM. Why is this so? Is there anyway I can enable HTTP
Pipelining? I'm running all this on Ubuntu 9.10 (not upgraded to lynx
yet! :)).

Any suggestions?

(The full code is attached)

Thanks,
-mandeep



More information about the Qt-interest-old mailing list