This is my files. I have some problems with that.
// 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();
}
My error messages. I have googled a lot and read the documentation:
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*)));
Add Q_OBJECT
macro to your class without ;
class Networking : public QObject
{
Q_OBJECT
public:
Networking();
void getNetReply();
And rebuild all project
Without this macro moc
cannot find your class and you can't use signals/slots mechanism. Also your class should be derivated from QObject
explicitly or implicitly.