网上的这个例子。
void Http::finishedSlot(QNetworkReply* reply)
{
// Reading attributes of the reply
// e.g. the HTTP status code
QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
// Or the target URL if it was a redirect:
QVariant redirectionTargetUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
// see CS001432 on how to handle this
// no error received?
if (reply->error() == QNetworkReply::NoError)
{
// Example 2: Reading bytes form the reply
QByteArray bytes = reply->readAll(); // bytes
// QString string(bytes); // string
recieve =
QString::fromUtf8(bytes);
// recieve = QString::fromUtf8(bytes);
// qDebug() << recieve;
}
// Some http error received
else
{
// handle errors here
}
// We receive ownership of the reply object
// and therefore need to handle deletion.
reply->deleteLater();
}
在程序中服务返回的结果(recieve)被直接处理了(
显示出来了)。我想将这个结果保存起来,我定义了一个实例变量recieve。
可是我怎样才能将结果返回到调用它的位置呢?
QUrl url(
http://XXXXX);nam->get(QNetworkRequest(url));
此时recieve还
没有返回值啊。