Unsolved QT Network Download Example does not run in parallel!
-
void DownloadManager::progress(qint64 done, qint64 total)
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QUrl url = reply->url();
QFileInfo info(QString(url.toEncoded().constData()));
qDebug()<<info.fileName()<<done<<total;
}connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(progress(qint64,qint64)));
i write like this. It seems like to output filename alternate.
But it didn't start next one until the current finish. -
@Limo You should show how you start those parallel downloads.
-
This post is deleted! -
@jsulm
in the example http://doc.qt.io/qt-5/qtnetwork-download-main-cpp.htmlvoid DownloadManager::execute() { QStringList args = QCoreApplication::instance()->arguments(); args.takeFirst(); // skip the first argument, which is the program's name if (args.isEmpty()) { printf("Qt Download example - downloads all URLs in parallel\n" "Usage: download url1 [url2... urlN]\n" "\n" "Downloads the URLs passed in the command-line to the local directory\n" "If the target file already exists, a .0, .1, .2, etc. is appended to\n" "differentiate.\n"); QCoreApplication::instance()->quit(); return; } foreach (QString arg, args) { QUrl url = QUrl::fromEncoded(arg.toLocal8Bit()); doDownload(url); } }
in this function,just instead the foreach with :
doDownload(url1); doDownload(url2);
-
This post is deleted! -
@Limo How big are the files?
How do you know it did not start second download while first one is running? -
@jsulm
they are 50~60MB.
i wrote this function:void DownloadManager::progress(qint64 done, qint64 total) { QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); QUrl url = reply->url(); QFileInfo info(QString(url.toEncoded().constData())); qDebug()<<info.fileName()<<done<<total; }
and
connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progress(qint64,qint64)));
if the second download has ran ,it may output its info.But i didn't saw the second download's info when the first is running.
-
@Limo Where do you call
connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progress(qint64,qint64)));
Do you call it for all replies?
-
void DownloadManager::doDownload(const QUrl &url) { QNetworkRequest request(url); QNetworkReply *reply = manager.get(request); #ifndef QT_NO_SSL connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(sslErrors(QList<QSslError>))); #endif connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progress(qint64,qint64))); currentDownloads.append(reply); }