예제 #1
0
QString HttpEng::get(QUrl url,const QString& proxyHost, const QString &proxyPort)
{
    timer_.start(TIME_OUT);
    content_.clear();
    if(!proxyHost.isEmpty()){
        proxy_.setHostName(proxyHost);
        proxy_.setPort(proxyPort.toInt());
        qnam_.setProxy(proxy_);
    }else{
        qnam_.setProxy(QNetworkProxy::NoProxy);
    }
    url_ = url;
    httpRequestAborted_ = false;
    reply_ = qnam_.get(QNetworkRequest(url));
    connect(reply_, SIGNAL(finished()),
            this, SLOT(httpFinished()));
    connect(reply_, SIGNAL(readyRead()),
            this, SLOT(httpReadyRead()));
    connect(reply_, SIGNAL(downloadProgress(qint64,qint64)),
            this, SLOT(updateDataReadProgress(qint64,qint64)));
    QEventLoop loop;
    connect(this, SIGNAL(engDone()), &loop, SLOT(quit()));
    loop.exec();
    return content_;
#if 0
    qApp->quit(); //------------>put here will never exit!!!!!!!!!!!
                  //              must execute after eventloop start
#endif         
}
예제 #2
0
void HttpWindow::startRequest(QUrl url) {
	reply = qnam.get(QNetworkRequest(url));
	connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
	connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
	connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this,
			SLOT(updateDataReadProgress(qint64,qint64)));
}
int SyncTabWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTabWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: on_pushButton_4_clicked(); break;
        case 1: on_pushButton_3_clicked(); break;
        case 2: on_pushButton_2_clicked(); break;
        case 3: on_pushButton_clicked(); break;
        case 4: downloadFile(); break;
        case 5: cancelDownload(); break;
        case 6: httpFinished(); break;
        case 7: httpReadyRead(); break;
        case 8: updateDataReadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        case 9: enableDownloadButton(); break;
        case 10: slotAuthenticationRequired((*reinterpret_cast< QNetworkReply*(*)>(_a[1])),(*reinterpret_cast< QAuthenticator*(*)>(_a[2]))); break;
        case 11: error((*reinterpret_cast< QNetworkReply::NetworkError(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 12;
    }
    return _id;
}
예제 #4
0
void FileDownloader::download(QUrl url) {
	QNetworkRequest req(url);
	req.setRawHeader("User-Agent", "SMPlayer");
	reply = manager->get(req);
	connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
            this, SLOT(updateDataReadProgress(qint64, qint64)));

	setLabelText(tr("Connecting to %1").arg(url.host()));
}
예제 #5
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::startRequest(QUrl url)
{
    m_reply = m_networkAccessManager.get(QNetworkRequest(url));
    connect(m_reply, SIGNAL(finished()),
        this, SLOT(httpFinished()));
    connect(m_reply, SIGNAL(readyRead()),
        this, SLOT(httpReadyRead()));
    connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)),
        this, SLOT(updateDataReadProgress(qint64,qint64)));
}
예제 #6
0
void GetBase::getBaseHttp()
{
    progressDialog = new QProgressDialog(this);
    fileHttp = new QFile("Yarn.dat");
    fileHttp->open(QIODevice::WriteOnly);
    url = "http://91.102.219.74/QtProject/Yarn/Base/Yarn.dat";
    //url = "http://91.102.219.74/QtProject/Yarn/Yarn.exe";

    reply = http.get(QNetworkRequest(url));
    connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead()));
    connect(reply,SIGNAL(finished()),this,SLOT(httpDone()));

    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,
            SLOT(updateDataReadProgress(qint64,qint64)));
    connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this,
            SLOT(updateDataReadProgress(qint64,qint64)));

    progressDialog->setLabelText(tr("Downloading DataBase ..."));
    progressDialog->setEnabled(true);
    progressDialog->exec();
}
void QFileDownload::startDeal()
{
    //QEventLoop loop;

    QFileInfo info(url.path());
    QString fileName(info.fileName());
    if(fileName.isEmpty())
        fileName = "index.html";
    qDebug()<<fileName;
    file = new QFile(fileName);
    qheader = new QNetworkRequest();
    /*******************************************/
     QString Range="bytes "+QString::number(startBytes)+"-";//告诉服务器从DownedSize起开始传输
        qDebug()<<"Range: "<<Range<<"\nstartBytes "<<startBytes<<"\n"<<fileName;
         qheader->setUrl(url);
         qheader->setRawHeader("Range",Range.toUtf8());
    /*******************************************/
    if(!file->open(QIODevice::WriteOnly|QIODevice::Append))
    {
        qDebug()<<"file open error !";
        delete file;
        file = 0;
        return ;
    }
    /****************************************************
    qheader = new QNetworkRequest() ;
    qheader->setUrl(url);
    QString Range="bytes "+QString::number(newSize)+"-";//告诉服务器从DownedSize起开始传输
    qheader->setRawHeader("Range",Range.toAscii());
    reply = manager->get(QNetworkRequest(*qheader));
    /****************************************************/


    reply = manager->get(QNetworkRequest(*qheader));
    _window->upDateProgressBar(newSize,totalSize);
    _window->ShowProgressBar();
    // 启动测速定时,1s。
    timer = new QTimer(this);
    timer->start(1000);
    //启动超时定时,30s。
    timer_15s = new QTimer(this);
    if(timer_15s->isActive())
        timer_15s->stop();
    timer_15s->start(15000);

    connect(timer,SIGNAL(timeout()),this,SLOT(updateSpeedTime()));
    //connect(timer_15s,SIGNAL(timeout()),this,SLOT(timeOut()));
    connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
    connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead()));
    connect(reply,SIGNAL(downloadProgress(qint64 ,qint64 )),this
            ,SLOT(updateDataReadProgress(qint64,qint64)));
}
void QFileDownload::stop(){
    file->flush();
    file->close();
    reply->deleteLater();
    timer->stop();
    timer_15s->stop();
    disconnect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
    reply->abort();
    disconnect(timer,SIGNAL(timeout()),this,SLOT(updateSpeedTime()));
    disconnect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead()));
    disconnect(reply,SIGNAL(downloadProgress(qint64 ,qint64 )),this
            ,SLOT(updateDataReadProgress(qint64,qint64)));
    startBytes = newSize;

}
예제 #9
0
int downloadDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: httpFinished(); break;
        case 1: httpReadyRead(); break;
        case 2: updateDataReadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
예제 #10
0
void DownLoadFun::down(STATUSID id, QString url)
{
    if(reply != NULL)
    {
        reply->abort();
    }

    m_id = id;

    QNetworkAccessManager *manager = new QNetworkAccessManager;
    reply = manager->get(QNetworkRequest(url));

    connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));

    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),
            this,SLOT(updateDataReadProgress(qint64,qint64)));
}
예제 #11
0
void jewelryUpdate::requestHttp(QUrl url)
{
    qDebug() <<url;
    QFileInfo info(url.path());
    QString fileName(info.fileName());
    if (fileName.isEmpty())
    {
      QMessageBox::critical(this, "系统消息", "版本文件错误或者丢失,请向程序开发人员联系!");
      return;
    }
    m_file = new QFile(fileName);
    if (!m_file->open(QIODevice::WriteOnly))
    {
      delete m_file;
      m_file = 0;
      return;
    }
    m_reply = m_manager.get(QNetworkRequest(url));
    connect(m_reply,SIGNAL(finished()),this,SLOT(httpFinished())); //更新完成后
    connect(m_reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead())); //有可用数据时
    connect(m_reply,SIGNAL(downloadProgress(qint64,qint64)), this,SLOT(updateDataReadProgress(qint64,qint64)));//更新进度条
}