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
QNetworkRequestyou can set an attribute withAttributeis an enum and there is a reserved code for just this situation,QNetworkRequest::User. (See: Attribute)In your
QNetworkReply, you can pull theQNetworkRequestwithrequest()then get theAttributefrom there withattribute()Bit of a hack, but I think it should work.