Тоже интересует эта тема, не могу понять, зачем у меня при запуске программа даже в httpFinished не заходит
C++ (Qt)
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include "get_html.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
PageDownloader html();
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setMainQmlFile(QLatin1String("qml/torrent_reminder/main.qml"));
viewer.showExpanded();
return app.exec();
}
C++ (Qt)
#ifndef GET_HTML_H
#define GET_HTML_H
#include <QtCore/QObject>
class QNetworkAccessManager;
class QNetworkReply;
class PageDownloader : public QObject
{
Q_OBJECT
public:
explicit PageDownloader(QObject *parent = 0);
private slots:
void httpFinished(QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
// QString get_code();
};
#endif // GET_HTML_H
C++ (Qt)
#include <QtCore/QFile>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include "get_html.h"
static const QString basePath = "http://www.prog.org.ru/topic_18530_0.html";
PageDownloader::PageDownloader(QObject *parent): QObject(parent)
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(httpFinished(QNetworkReply *)));
manager->get(QNetworkRequest(QUrl(basePath)));
}
void PageDownloader::httpFinished(QNetworkReply *reply)
{
QFile file("file.htm");
if (file.open(QIODevice::WriteOnly))
{
file.write(reply->readAll());
file.flush();
}
reply->deleteLater();
reply = 0;
}