#include <QCoreApplication>#include "sbnetwork.h"#include <QDebug>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); qDebug() << "Start"; SBNetwork w; return 0;}
#ifndef SBNETWORK_H#define SBNETWORK_H#include <QObject>#include <QNetworkAccessManager>#include <QNetworkReply>#include <QDebug>#include <QFile>#include <QEventLoop>#include <QTimer>class SBNetwork : public QObject{ Q_OBJECTpublic: explicit SBNetwork(QObject *parent = 0);private: QNetworkAccessManager manager;public slots: void replyFinished(QNetworkReply*);};#endif // SBNETWORK_H
#include "sbnetwork.h"SBNetwork::SBNetwork(QObject *parent) : QObject(parent){ connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); QFile file("d:/1.txt"); if (!file.open(QIODevice::ReadOnly)) return; while (!file.atEnd()) { QString line(file.readLine()); manager.get(QNetworkRequest(QUrl(line.simplified()))); QEventLoop loop; QTimer::singleShot(1000, &loop, SLOT(quit())); loop.exec(); } qDebug() << "Ok";}void SBNetwork::replyFinished(QNetworkReply * n){ qDebug() << n->readAll();}