Get the function that initiated QNetworkRequest in replyFinished ()

i has the following problem:

I have a Foo class that encapsulates web-api. The interface has the following functions:

Foo :: addItem (QString id)
Foo :: updateItem (QString id)

both functions initiate a QNetworkRequest with the same URL, but the data usage is different. Therefore, I need to know in the slot function Foo :: replyFinished (QNetworkReply * wf_reply) where QNetworkRequest came from.

How would you solve this?

I could use a variable to save the QNetworkRequest address, to compare it later with wf_reply-> request (), but it seems hacked to me. Given that you can call addItem () or updateItem () a hundred times before replyFinished () is executed for the first time. A better way would be to add sting or integer to a QNetworkRequest that contains the function name or identifier.

+5
source share
2 answers

In the source QNetworkRequestyou can set the attribute

setAttribute(Attribute code, const QVariant & value)

Attribute- This listing, and there is a reserved code to this situation QNetworkRequest::User. (See: Attribute )

In QNetworkReplyyou can pull QNetworkRequestwith request(), then from there Attributewithattribute()

, , .

+3

:

0

All Articles