力战者
力战者,天酬之!

QT    同步下载

#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QtCore>
#include <iostream>
using namespace std ;
class TT : public QObject
{
    Q_OBJECT
public:
    static QString getHtml(QString url)
    {
        QNetworkAccessManager *manager = new QNetworkAccessManager();
        QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
        QByteArray responseData;
        QEventLoop eventLoop;
        connect(manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
        eventLoop.exec();       //block until finish
        responseData = reply->readAll();
        return QString(responseData);
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QString data = TT::getHtml(QString("http://outofmemory.cn );
    cout<<data.toStdString()<<endl;
    return a.exec();
}

 

posted on 2019-07-21 17:58  力战者  阅读(177)  评论(0编辑  收藏  举报