Question

This is my first post here, and I'm fairly new to Qt.

I am using Qwebkit in order to load a web page, and I'm interested in NOT fully load some resources from web. To be specific, I'm trying to get only the size of jpg files and not the image data from within the jpg's binary data (not HTML tags). For doing so, I have re-implemented the createRequest method of QNAM to do as follow:

QNetworkReply *NetworkAccessManager::createRequest(Operation op,const QNetworkRequest & req,QIODevice * outgoingData )
{


    if (req.url().path().endsWith("jpg"))
    {
        CustomReply *reply = new CustomReply(QNetworkAccessManager::createRequest(op, req, outgoingData));
        return reply->getQNR();
    }else{
        return QNetworkAccessManager::createRequest(op, req, outgoingData);
    }
}

Then I connect some signal in my CustomReply class to append the coming data into a QByteArray, then I process the QByteArray to see if I have the marker I'm looking for. Now here I don't know how to proceed. What I want to do after this is closing the connection (to not download more) and passing the reply with the data I have received through CustomReply::getQNR(). I need to implement a function to set the content of my reply to the QByteArray I stored, and I have read this and that but couldn't solve my problem.

Thank you in advance.

Was it helpful?

Solution 2

I did as described here and solved my problem. I was missing the offset, so every time readData() was called, the data was read from the beginning. In order to close the connection I connect the finish signal of CustomReply into original QNReply. When I get enough data, I emit finish signal to close the connection. Calling abort or close will result in ERROR 5 (although you can handle the error but I find working with signal a bit cooler).

Thank you everybody.

OTHER TIPS

I'm not 100% clear on your question but if you're trying to return the value of the reply you received to another QByteArray just set up an additional signal which is either fired on completion or called with emit and pass the value across that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top