QNetworkReply回复在finishedSlot中没有成员

时间:2012-09-13 01:53:39

标签: c++ web-services qt

Qt Creator用作正在开发的这个小应用程序的ide

我正在尝试使用QNetworkAccessManager从网站中检索一些信息。在将请求“发布”到Web之后,触发finished()信号,但是传递给finishedSlot()函数的指针似乎没有指向实例化对象,它只是ponter的地址。启动请求的按钮单击代码和finishedSlot()方法的代码如下所示。

在观察窗口中,我希望在“回复”旁边看到一个三角形,当expaned显示QNetworkReply对象的所有数据成员时。相反,它有一个@ 0x80c770的值,看起来像指针地址。

我很感激任何能帮助我理解为什么我的指针不会指向QNetworkReply对象的人的输入。

void MainWindow::on_btnGetOAuthToken_clicked()
{


    QUrl serviceUrl("https://api.ProPhotoWebsite.com/services/oauth/authorize.mg");
    QUrl postData;
    postData.addQueryItem("method", "ProPhotoWebsite.auth.getRequestToken");
    postData.addQueryItem("oauth_consumer_key", "AAAAAAAAAAAAAAAAAAAAAAAA"); //example key
    postData.addQueryItem("oauth_nonce",QUuid::createUuid().toString());
    postData.addQueryItem("oauth_signature_method","PLAINTEXT");  
    postData.addQueryItem("oauth_signature","999999999999999999999999999"); //example
    postData.addQueryItem("oauth_timestamp", QString::number(QDateTime::currentMSecsSinceEpoch()/1000));
    postData.addQueryItem("oauth_version","1.0");

    //...
    QNetworkRequest request(serviceUrl);
    request.setHeader(QNetworkRequest::ContentTypeHeader,
                      "application/x-www-form-urlencoded");

    // Call the webservice
    QNetworkAccessManager *nam = new QNetworkAccessManager(this);
    connect(nam, SIGNAL(finished(QNetworkReply*)),
            SLOT(finishedSlot(QNetworkReply*)));
    nam->post(request,postData.encodedQuery());

}

void MainWindow::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)
    {

        QByteArray bytes = reply->readAll();  // bytes
        QString string(bytes); // string
        ui->lblWarning->setText(string);

    }
    else
    {
        // handle errors here
    }

    // need to dispose reply
    delete reply;
}

0 个答案:

没有答案