连接功能BlackBerry-10出错

时间:2012-12-18 07:32:58

标签: c++ http blackberry-10

您好我正在尝试发送HTTP GET请求并使用函数接收结果。但是我收到了这个错误:

  

没有用于调用'HttpNetworkRequest :: connect的匹配函数(QNetworkAccessManager *&,const char *,RequestFinishFunction&,const)        字符*)'

connect函数位于此HttpNetworkRequest.cpp文件中

#include "HttpNetworkRequest.hpp"
#include <QObject>
#include <QIODevice>
#include <QDir>

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/XmlDataModel>
#include <RequestFinishFunction.hpp>
using namespace bb::cascades;

HttpNetworkRequest::HttpNetworkRequest(bb::cascades::Application *app)
: QObject(app)
{
QNetworkRequest networkRequest = QNetworkRequest();
networkRequest.setUrl(QUrl("http://www.blackberry.com"));
RequestFinishFunction req;
QNetworkAccessManager *networkAccessManager = new QNetworkAccessManager;
bool res =        connect(networkAccessManager,SIGNAL(finished(QNetworkReply*)),
    req,SLOT(requestFinished()));
Q_ASSERT(res);
Q_UNUSED(res);
networkAccessManager->get(networkRequest);
}

包含的RequestFinishFunction.hpp

#ifndef REQUESTFINISHFUNCTION_HPP_
#define REQUESTFINISHFUNCTION_HPP_
#include <bb/cascades/ActivityIndicator>
#include <QObject>
#include <QObject>
class RequestFinishFunction : QObject
{
public slots:
void requestFinished(QNetworkReply* reply);
};
#endif /* REQUESTFINISHFUNCTION_HPP_ */

RequestFinishFunction.cpp文件是

#include <bb/cascades/ActivityIndicator>
#include <QObject>
#include <QObject>
#include <RequestFinishFunction.hpp>
void RequestFinishFunction::requestFinished(QNetworkReply* reply)
{
    reply->deleteLater();
}

1 个答案:

答案 0 :(得分:2)

连接方法的语法

  

bool QObject :: connect(const QObject * sender,const char * signal,const QObject * receiver,const char * method,Qt :: ConnectionType type = Qt :: AutoConnection)

我们必须传递发件人和发件人的 参考 。接收机。

您没有发送接收器的参考。您有两种选择。

1)使用&amp;发送req参考。连接方法调用中的运算符

替换

  

connect(networkAccessManager,SIGNAL(已完成(QNetworkReply *)),req,SLOT(requestFinished()));

  

connect(networkAccessManager,SIGNAL(已完成(QNetworkReply *)),&amp; req,SLOT(requestFinished()));

2)将req声明为指针

替换

  

RequestFinishFunction req;

  

RequestFinishFunction * req;