这是我的档案。我有一些问题。
// networking.h
#ifndef NETWORKING_H
#define NETWORKING_H
#include <QNetworkReply>
class Networking
{
public:
Networking();
void getNetReply();
void replyFinished(QNetworkReply*);
};
#endif // NETWORKING_H
//networking.cpp
#include "networking.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QUrl>
#include <QNetworkRequest>
#include <QObject>
Networking::Networking()
{
}
void Networking::getNetReply(){
QNetworkAccessManager * man;
man = new QNetworkAccessManager(this);
qDebug() << "Getting content..." << endl;
QNetworkRequest request(QUrl("http://www.google.pl"));
qDebug() << "Network request..." << endl;
QNetworkReply * NetRepl;
QObject::connect(man, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply*)));
NetRepl = man->get(request);
qDebug() << "Network reply..." << endl;
qDebug() << "Connecting..." << endl;
}
void Networking::replyFinished(QNetworkReply* reply){
// my code
reply->readAll();
}
我的错误消息。我已经google了很多并阅读了文档:
错误:没有匹配函数来调用'QNetworkAccessManager :: QNetworkAccessManager(Networking * const)' man = new QNetworkAccessManager(this); ^
20:错误:没有匹配函数来调用'QObject :: connect(QNetworkAccessManager *&amp;,const char *,Networking * const,const char *)' QObject :: connect(man,SIGNAL(已完成(QNetworkReply )),这个,SLOT(replyFinished(QNetworkReply ))); ^
答案 0 :(得分:2)
在没有Q_OBJECT
;
宏
class Networking : public QObject
{
Q_OBJECT
public:
Networking();
void getNetReply();
重建所有项目
如果没有此宏moc
无法找到您的课程,您就无法使用信号/插槽机制。此外,您的类应该显式或隐式地从QObject
派生。