gpt4 book ai didi

c++ - 错误 : no matching function for call to 'QNetworkAccessManager::QNetworkAccessManager(Networking* const)'

转载 作者:行者123 更新时间:2023-11-30 04:01:26 28 4
gpt4 key购买 nike

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

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

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

error: no matching function for call to QNetworkAccessManager::QNetworkAccessManager(Networking* const) man = new QNetworkAccessManager(this);

20: error: no matching function for call to 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 派生。

关于c++ - 错误 : no matching function for call to 'QNetworkAccessManager::QNetworkAccessManager(Networking* const)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25765122/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com