[Qt-interest] QT Networking: Is there a way to pass custom info in network request?

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Fri Jul 2 13:12:16 CEST 2010


I'm using QNAM and co to fetch data from a backend system.

The data is fetched in a "paged" manner with certain params set in the
network request to fetch a page worth of data (these params are not
simple page=1/2 etc type, but somewhat more cryptic...some uuid like
thingy).

Now to speed up things, I put an extra request which is of the next
page. But when the finished() signal is emitted I need to find out if
the reply is for the current page or the next one that I tried to
pre-fetch (I need this info because i do different processing in the 2
cases).

There are a lot of ways by which I can map which "page" the network
reply corresponds  to. eg: use a map/hash with QUrl as the key and
page num as the value. In reply I can extract the "request" URL and
then get the page num.

I've seen QNetworkRequest::originatingObject() also. I could use this
to attach some object which has the page info and keep it around till
I get a reply back and then use the object to get the page num.

But all of them look too cumbersome for such a trivial task (and I'm lazy :)).

Is there a simple way by which I can attach my custom info (i.e a page
number here) to  a network request object....and when the finished
signal is emitted, extract the QNetworkRequest object and get my
custom info out?

Any suggestion is much appreciated! :)

Thanks,
-mandeep



More information about the Qt-interest-old mailing list