i have following problem:
I have a class Foo which encapsulates a web-api. the interface has following functions:
Foo::addItem( QString id )
Foo::updateItem( QString id )
both function initiate a QNetworkRequest with the same URL but the usage of the data is different. Therefore i need to know in slot function Foo::replyFinished( QNetworkReply *wf_reply ) from where the QNetworkRequest originated.
How would you solve this?
I could use variable to store the adress of the QNetworkRequest to compare it later to wf_reply->request() but this seems like a hack to me. Considering you can call addItem() or updateItem() hundred times before replyFinished() is executed for the first time. The best way would be to add a sting or integer to QNetworkRequest which contains the function name or id.
In your original QNetworkRequest
you can set an attribute with
setAttribute(Attribute code, const QVariant & value)
Attribute
is an enum and there is a reserved code for just this situation, QNetworkRequest::User
. (See: Attribute)
In your QNetworkReply
, you can pull the QNetworkRequest
with request()
then get the Attribute
from there with attribute()
Bit of a hack, but I think it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With