错误:没有匹配函数来调用' QNetworkAccessManager :: QNetworkAccessManager(Networking * const)'

时间:2014-09-10 12:10:07

标签: c++ qt qt5 qnetworkaccessmanager

这是我的档案。我有一些问题。

   // 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 )));                                                                                                        ^

1 个答案:

答案 0 :(得分:2)

在没有Q_OBJECT

的情况下向您的班级添加;
class Networking : public QObject
{
Q_OBJECT
public:
    Networking();
    void getNetReply();

重建所有项目

如果没有此宏moc无法找到您的课程,您就无法使用信号/插槽机制。此外,您的类应该显式或隐式地从QObject派生。