您好我正在尝试发送 HTTP GET 请求并使用函数接收结果。但我收到此错误:
调用 'HttpNetworkRequest::connect(QNetworkAccessManager*&, const char*, RequestFinishFunction&, const char*)' 没有匹配的函数
连接函数在这个 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();
}