系统相关
首页 > 系统相关> > QT单进程下载

QT单进程下载

作者:互联网

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();
}

 

标签:responseData,QT,int,eventLoop,manager,QString,进程,include,下载
来源: https://www.cnblogs.com/lizhanzhe/p/QT.html