我正在尝试使用头文件中的以下代码下载网页的源代码:
#include <QObject>
#include <QHttp>
#include <QtNetwork>
#include <QFile>
#include <QDebug>
class CDownloader : public QObject
{
Q_OBJECT
public:
explicit CDownloader(QObject *parent = 0);
void Do_Download();
signals:
public slots:
void result(QNetworkReply*);
private:
QNetworkAccessManager *manager;
QNetworkReply *reply;
QNetworkAccessManager qnam;
};
#endif // CDOWNLOADER_H
和源文件:
#include "cdownloader.h"
CDownloader::CDownloader(QObject *parent) :
QObject(parent)
{
}
void CDownloader::Do_Download()
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(result(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://www.google.com")));
}
void CDownloader::result(QNetworkReply *reply)
{
qDebug() << "loading complete";
}
和按钮代码:
void MainWindow::on_download_clicked()
{
CDownloader cDown;
cDown.Do_Download();
}
但是 qDebug 永远不会在结果槽中调用。我错过了什么?