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



这是我的文件。我对此有一些问题。

   // 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();
}

我的错误消息。我在谷歌上搜索了很多并阅读了文档:

错误:没有可用于调用的匹配函数QNetworkAccessManager::QNetworkAccessManager(Networking* const)man = new QNetworkAccessManager(this)

20:错误:对的调用没有匹配函数QObject::connect(QNetworkAccessManager*&, const char*, Networking*const, const char*)QObject::connect(man, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply*)));

在没有; 的情况下将Q_OBJECT宏添加到类中

class Networking : public QObject
{
Q_OBJECT
public:
    Networking();
    void getNetReply();

并重建所有项目

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

相关内容

  • 没有找到相关文章

最新更新