void BlFile::sync() { BL_FUNC_DEBUG // if (!exists() { QFileInfo fileInfo(m_file); QString filename(fileInfo.fileName()); QString user = g_confpr->value(CONF_LOGIN_USER); QString dbname = g_confpr->value(CONF_DBNAME); #ifdef Q_OS_WIN32 QString platform = "MS_WIN"; #else QString platform = "LINUX"; #endif QString url = "http://www.bulmages.com/bulmaincloud/"+platform+"/"+user+"/"+dbname+"/"+filename; fprintf(stderr, "Iniciando descarga %s\n", url.toLatin1().constData()); manager = new QNetworkAccessManager(this); QNetworkRequest request; request.setUrl(QUrl(url)); request.setRawHeader("User-Agent", "BgBrowser 1.0"); QNetworkReply *reply = manager->get(request); connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64))); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>))); connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); while (reply->isRunning()) { QApplication::processEvents(); } // end while // }// end if url = "http://www.bulmages.com/bulmaincloud/ALL/"+user+"/"+dbname+"/"+filename; fprintf(stderr, "Iniciando descarga %s\n", url.toLatin1().constData()); request.setUrl(QUrl(url)); reply = manager->get(request); while (reply->isRunning()) { QApplication::processEvents(); } // end while if (reply->error() == QNetworkReply::NoError) { return; } // end if url = "http://www.bulmages.com/bulmaincloud/ALL/ALL/"+filename; fprintf(stderr, "Iniciando descarga %s\n", url.toLatin1().constData()); request.setUrl(QUrl(url)); reply = manager->get(request); while (reply->isRunning()) { QApplication::processEvents(); } // end while }
void testPut() { #if defined(USE_QNAM) && QT_VERSION <= QT_VERSION_CHECK(5, 5, 0) QSKIP("This test is broken with Qt < 5.5, the fix is 9286a8e5dd97c5d4d7e0ed07a73d4ce7240fdc1d in qtbase"); #endif const QString aDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); QVERIFY(QDir::temp().mkpath(aDir)); const QString aFile = aDir + QStringLiteral("/accessmanagertest-data"); const QByteArray content = "We love free software!"; QBuffer buffer; buffer.setData(content); QVERIFY(buffer.open(QIODevice::ReadOnly)); QFile::remove(aFile); QNetworkReply *reply = manager()->put(QNetworkRequest(QUrl::fromLocalFile(aFile)), &buffer); QSignalSpy spy(reply, SIGNAL(finished())); QVERIFY(reply->isRunning()); QVERIFY(spy.wait()); QVERIFY(QFile::exists(aFile)); QFile f(aFile); QVERIFY(f.open(QIODevice::ReadOnly)); QCOMPARE(f.readAll(), content); QFile::remove(aFile); }
void ImageDownloader::load(){ QUrl url = QUrl::fromUserInput(QString(picture->filename)); if (url.isValid()) { QEventLoop loop; QNetworkRequest request(url); connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(saveImage(QNetworkReply *))); QNetworkReply *reply = manager.get(request); while (reply->isRunning()) { loop.processEvents(); sleep(1); } }
void ChooseFileDlg::onFileSelect(bool) { QString path = QFileDialog::getOpenFileName(this, tr("Open File"), NULL, tr("All files *.*")); QFile *file = new QFile(path); if (!file->exists() || !file->open(QIODevice::ReadOnly)) return; QProgressDialog progress(tr("Uploading..."), tr("Abort"), 0, 100, this); progress.setMinimumDuration(0); QHttpPart httpFilePart; httpFilePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"file\"; filename=\"%1\"").arg(QFileInfo(path).fileName()))); httpFilePart.setBodyDevice(file); QHttpMultiPart *httpMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); httpMultiPart->append(httpFilePart); QNetworkAccessManager manager; QNetworkReply *reply = manager.post(QNetworkRequest(QUrl("http://127.0.0.1:3000/media/upload")), httpMultiPart); connect(reply, &QNetworkReply::uploadProgress, [&](qint64 bytesSent, qint64 bytesTotal){ if (bytesSent && bytesTotal) progress.setValue((100 * bytesSent) / bytesTotal); }); file->setParent(httpMultiPart); httpMultiPart->setParent(reply); connect(&progress, &QProgressDialog::canceled, [&]() { reply->abort(); }); while (reply->isRunning()) { QCoreApplication::processEvents(); } if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::OperationCanceledError) QMessageBox::warning(this, tr("Failed to upload"), reply->errorString()); return; } QByteArray content = reply->readAll(); qDebug() << content; }
bool QgsGlobePluginDialog::validateRemoteUri( const QString &uri, QString &errMsg ) const { QUrl url( uri ); QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance(); QNetworkReply *reply = nullptr; while ( true ) { QNetworkRequest req( url ); req.setRawHeader( "User-Agent", "Wget/1.13.4" ); reply = nam->get( req ); QTimer timer; QEventLoop loop; QObject::connect( &timer, SIGNAL( timeout() ), &loop, SLOT( quit() ) ); QObject::connect( reply, SIGNAL( finished() ), &loop, SLOT( quit() ) ); timer.setSingleShot( true ); timer.start( 500 ); loop.exec(); if ( reply->isRunning() ) { // Timeout reply->close(); delete reply; errMsg = tr( "Timeout" ); return false; } QUrl redirectUrl = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl(); if ( redirectUrl.isValid() && url != redirectUrl ) { delete reply; url = redirectUrl; } else { break; } } errMsg = reply->error() == QNetworkReply::NoError ? QString() : reply->errorString(); delete reply; return errMsg.isEmpty(); }
double donationDialog::EUR2BTC() { QNetworkReply *rep = ((MainWindow*)parent())->mgr->get(QNetworkRequest(QUrl("https://blockchain.info/de/tobtc?currency=EUR&value=1"))); QByteArray raw; rep->ignoreSslErrors(); lineEdit_payment2->setText(tr("getting current exchange rate...")); comboBox->setEnabled(false); horizontalSlider->setEnabled(false); pushButton->setEnabled(false); ((MainWindow*)parent())->timeout.start(); while(rep->isRunning()) { QCoreApplication::processEvents(); if(((MainWindow*)parent())->timeout.hasExpired(3000)) { rep->abort(); } } comboBox->setEnabled(true); horizontalSlider->setEnabled(true); pushButton->setEnabled(true); if(rep->error()) { QMessageBox::warning(this, APPNAME, tr("Current exchange rate could not be determined!\n\nPlease specify the desired amount manually...")); return 0.0; } raw = rep->readAll(); rep->deleteLater(); return raw.toDouble(); }