Originally Posted by
unit
From QT Doc:
QNetworkRequest::User. Special type. Additional information can be passed in QVariants with types ranging from User to UserMax. The default implementation of Network Access will ignore any request attributes in this range and it will not produce any attributes in this range in replies. The range is reserved for extensions of QNetworkAccessManager.
I am pretty certain that is simply saying that the library will not touch anyhthing you put in that range, not that it won't allow you to pass information through them. Hence their choice of name "User" for the variable. Attributes put there stay there, they just don't automatically get forwarded to the resultant QNetworkReply* object because QNetworkAccessManager doesn't know if it is supposed to or not.
So you can still access it via `reply->request()->attribute(QNetworkRequest::User)`. Or you can insert it into the reply yourself:
...
QNetworkRequest request;
request.
setUrl(QUrl(strUrl
));
request.setAttribute(QNetworkRequest::User, strTest1);
request.setAttribute(QNetworkRequest::UserMax, strCategory);
//accessManager->get(request);
QNetworkReply* reply = accessManager->get(request);
reply->setAttribute(QNetworkRequest::User, strTest1);
reply->setAttribute(QNetworkRequest::UserMax, strCategory);
...
... net_finished(QNetworkReply *reply)
{
reply->deleteLater();
if (reply->error())
return;
QString strTest1
= reply
->attribute
(QNetworkRequest
::User).
toString();
QString strCategory
= reply
->attribute
(QNetworkRequest
::UserMax).
toString();
//Or:
//QString strTest1 = reply->request()->attribute(QNetworkRequest::User).toString();
//QString strCategory = reply->request()->attribute(QNetworkRequest::UserMax).toString();
...
...
QNetworkRequest request;
request.setUrl(QUrl(strUrl));
request.setAttribute(QNetworkRequest::User, strTest1);
request.setAttribute(QNetworkRequest::UserMax, strCategory);
//accessManager->get(request);
QNetworkReply* reply = accessManager->get(request);
reply->setAttribute(QNetworkRequest::User, strTest1);
reply->setAttribute(QNetworkRequest::UserMax, strCategory);
...
... net_finished(QNetworkReply *reply)
{
reply->deleteLater();
if (reply->error())
return;
QString strTest1 = reply->attribute(QNetworkRequest::User).toString();
QString strCategory = reply->attribute(QNetworkRequest::UserMax).toString();
//Or:
//QString strTest1 = reply->request()->attribute(QNetworkRequest::User).toString();
//QString strCategory = reply->request()->attribute(QNetworkRequest::UserMax).toString();
QByteArray bData = reply->readAll();
...
To copy to clipboard, switch view to plain text mode
Both methods work for me at least. But I was just throwing code at a similar problem a few weeks ago until it started to function, so YMMV.
Bookmarks