A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQNetworkAccessManager</id>
		<title>C++/Qt/QNetworkAccessManager - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQNetworkAccessManager"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QNetworkAccessManager&amp;action=history"/>
		<updated>2026-04-18T18:40:36Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QNetworkAccessManager&amp;diff=1018&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QNetworkAccessManager&amp;diff=1018&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QNetworkAccessManager&amp;diff=1019&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QNetworkAccessManager&amp;diff=1019&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:33Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Download from URL==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#include &amp;lt;QCoreApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QFile&amp;gt;&lt;br /&gt;
#include &amp;lt;QFileInfo&amp;gt;&lt;br /&gt;
#include &amp;lt;QList&amp;gt;&lt;br /&gt;
#include &amp;lt;QNetworkAccessManager&amp;gt;&lt;br /&gt;
#include &amp;lt;QNetworkRequest&amp;gt;&lt;br /&gt;
#include &amp;lt;QNetworkReply&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QTimer&amp;gt;&lt;br /&gt;
#include &amp;lt;QUrl&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
class DownloadManager: public QObject&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
    QNetworkAccessManager manager;&lt;br /&gt;
    QList&amp;lt;QNetworkReply *&amp;gt; currentDownloads;&lt;br /&gt;
public:&lt;br /&gt;
    DownloadManager();&lt;br /&gt;
    void doDownload(const QUrl &amp;amp;url);&lt;br /&gt;
    QString saveFileName(const QUrl &amp;amp;url);&lt;br /&gt;
    bool saveToDisk(const QString &amp;amp;filename, QIODevice *data);&lt;br /&gt;
public slots:&lt;br /&gt;
    void execute();&lt;br /&gt;
    void downloadFinished(QNetworkReply *reply);&lt;br /&gt;
};&lt;br /&gt;
DownloadManager::DownloadManager()&lt;br /&gt;
{&lt;br /&gt;
    connect(&amp;amp;manager, SIGNAL(finished(QNetworkReply*)),&lt;br /&gt;
            SLOT(downloadFinished(QNetworkReply*)));&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::doDownload(const QUrl &amp;amp;url)&lt;br /&gt;
{&lt;br /&gt;
    QNetworkRequest request(url);&lt;br /&gt;
    QNetworkReply *reply = manager.get(request);&lt;br /&gt;
    currentDownloads.append(reply);&lt;br /&gt;
}&lt;br /&gt;
QString DownloadManager::saveFileName(const QUrl &amp;amp;url)&lt;br /&gt;
{&lt;br /&gt;
    QString path = url.path();&lt;br /&gt;
    QString basename = QFileInfo(path).fileName();&lt;br /&gt;
    if (basename.isEmpty())&lt;br /&gt;
        basename = &amp;quot;download&amp;quot;;&lt;br /&gt;
    if (QFile::exists(basename)) {&lt;br /&gt;
        // already exists, don&amp;quot;t overwrite&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        basename += &amp;quot;.&amp;quot;;&lt;br /&gt;
        while (QFile::exists(basename + QString::number(i)))&lt;br /&gt;
            ++i;&lt;br /&gt;
        basename += QString::number(i);&lt;br /&gt;
    }&lt;br /&gt;
    return basename;&lt;br /&gt;
}&lt;br /&gt;
bool DownloadManager::saveToDisk(const QString &amp;amp;filename, QIODevice *data)&lt;br /&gt;
{&lt;br /&gt;
    QFile file(filename);&lt;br /&gt;
    if (!file.open(QIODevice::WriteOnly)) {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Could not open %s for writing: %s\n&amp;quot;,&lt;br /&gt;
                qPrintable(filename),&lt;br /&gt;
                qPrintable(file.errorString()));&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
    file.write(data-&amp;gt;readAll());&lt;br /&gt;
    file.close();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::execute()&lt;br /&gt;
{&lt;br /&gt;
    QStringList args = QCoreApplication::instance()-&amp;gt;arguments();&lt;br /&gt;
    args.takeFirst();           // skip the first argument, which is the program&amp;quot;s name&lt;br /&gt;
    if (args.isEmpty()) {&lt;br /&gt;
        printf(&amp;quot;Qt Download example - downloads all URLs in parallel\n&amp;quot;&lt;br /&gt;
               &amp;quot;Usage: download url1 [url2... urlN]\n&amp;quot;&lt;br /&gt;
               &amp;quot;\n&amp;quot;&lt;br /&gt;
               &amp;quot;Downloads the URLs passed in the command-line to the local directory\n&amp;quot;&lt;br /&gt;
               &amp;quot;If the target file already exists, a .0, .1, .2, etc. is appended to\n&amp;quot;&lt;br /&gt;
               &amp;quot;differentiate.\n&amp;quot;);&lt;br /&gt;
        QCoreApplication::instance()-&amp;gt;quit();&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    foreach (QString arg, args) {&lt;br /&gt;
        QUrl url = QUrl::fromEncoded(arg.toLocal8Bit());&lt;br /&gt;
        doDownload(url);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::downloadFinished(QNetworkReply *reply)&lt;br /&gt;
{&lt;br /&gt;
    QUrl url = reply-&amp;gt;url();&lt;br /&gt;
    if (reply-&amp;gt;error()) {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Download of %s failed: %s\n&amp;quot;,&lt;br /&gt;
                url.toEncoded().constData(),&lt;br /&gt;
                qPrintable(reply-&amp;gt;errorString()));&lt;br /&gt;
    } else {&lt;br /&gt;
        QString filename = saveFileName(url);&lt;br /&gt;
        if (saveToDisk(filename, reply))&lt;br /&gt;
            printf(&amp;quot;Download of %s succeded (saved to %s)\n&amp;quot;,&lt;br /&gt;
                   url.toEncoded().constData(), qPrintable(filename));&lt;br /&gt;
    }&lt;br /&gt;
    currentDownloads.removeAll(reply);&lt;br /&gt;
    reply-&amp;gt;deleteLater();&lt;br /&gt;
    if (currentDownloads.isEmpty())&lt;br /&gt;
        // all downloads finished&lt;br /&gt;
        QCoreApplication::instance()-&amp;gt;quit();&lt;br /&gt;
}&lt;br /&gt;
int main(int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
    QCoreApplication app(argc, argv);&lt;br /&gt;
    DownloadManager manager;&lt;br /&gt;
    QTimer::singleShot(0, &amp;amp;manager, SLOT(execute()));&lt;br /&gt;
    app.exec();&lt;br /&gt;
}&lt;br /&gt;
#include &amp;quot;main.moc&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Download manager==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef TEXTPROGRESSBAR_H&lt;br /&gt;
#define TEXTPROGRESSBAR_H&lt;br /&gt;
#include &amp;lt;QString&amp;gt;&lt;br /&gt;
class TextProgressBar&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
    TextProgressBar();&lt;br /&gt;
    void clear();&lt;br /&gt;
    void update();&lt;br /&gt;
    void setMessage(const QString &amp;amp;message);&lt;br /&gt;
    void setStatus(qint64 value, qint64 maximum);&lt;br /&gt;
private:&lt;br /&gt;
    QString message;&lt;br /&gt;
    qint64 value;&lt;br /&gt;
    qint64 maximum;&lt;br /&gt;
    int iteration;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;textprogressbar.h&amp;quot;&lt;br /&gt;
#include &amp;lt;QByteArray&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
TextProgressBar::TextProgressBar()&lt;br /&gt;
    : value(0), maximum(-1), iteration(0)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
void TextProgressBar::clear()&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
    fflush(stdout);&lt;br /&gt;
    iteration = 0;&lt;br /&gt;
    value = 0;&lt;br /&gt;
    maximum = -1;&lt;br /&gt;
}&lt;br /&gt;
void TextProgressBar::update()&lt;br /&gt;
{&lt;br /&gt;
    ++iteration;&lt;br /&gt;
    if (maximum &amp;gt; 0) {&lt;br /&gt;
        // we know the maximum&lt;br /&gt;
        // draw a progress bar&lt;br /&gt;
        int percent = value * 100 / maximum;&lt;br /&gt;
        int hashes = percent / 2;&lt;br /&gt;
        QByteArray progressbar(hashes, &amp;quot;#&amp;quot;);&lt;br /&gt;
        if (percent % 2)&lt;br /&gt;
            progressbar += &amp;quot;&amp;gt;&amp;quot;;&lt;br /&gt;
        printf(&amp;quot;\r[%-50s] %3d%% %s     &amp;quot;,&lt;br /&gt;
               progressbar.constData(),&lt;br /&gt;
               percent,&lt;br /&gt;
               qPrintable(message));&lt;br /&gt;
    } else {&lt;br /&gt;
        // we don&amp;quot;t know the maximum, so we can&amp;quot;t draw a progress bar&lt;br /&gt;
        int center = (iteration % 48) + 1; // 50 spaces, minus 2&lt;br /&gt;
        QByteArray before(qMax(center - 2, 0), &amp;quot; &amp;quot;);&lt;br /&gt;
        QByteArray after(qMin(center + 2, 50), &amp;quot; &amp;quot;);&lt;br /&gt;
        printf(&amp;quot;\r[%s###%s]      %s      &amp;quot;,&lt;br /&gt;
               before.constData(), after.constData(), qPrintable(message));&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void TextProgressBar::setMessage(const QString &amp;amp;m)&lt;br /&gt;
{&lt;br /&gt;
    message = m;&lt;br /&gt;
}&lt;br /&gt;
void TextProgressBar::setStatus(qint64 val, qint64 max)&lt;br /&gt;
{&lt;br /&gt;
    value = val;&lt;br /&gt;
    maximum = max;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef DOWNLOADMANAGER_H&lt;br /&gt;
#define DOWNLOADMANAGER_H&lt;br /&gt;
#include &amp;lt;QFile&amp;gt;&lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
#include &amp;lt;QQueue&amp;gt;&lt;br /&gt;
#include &amp;lt;QTime&amp;gt;&lt;br /&gt;
#include &amp;lt;QUrl&amp;gt;&lt;br /&gt;
#include &amp;lt;QNetworkAccessManager&amp;gt;&lt;br /&gt;
#include &amp;quot;textprogressbar.h&amp;quot;&lt;br /&gt;
class DownloadManager: public QObject&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    DownloadManager(QObject *parent = 0);&lt;br /&gt;
    void append(const QUrl &amp;amp;url);&lt;br /&gt;
    void append(const QStringList &amp;amp;urlList);&lt;br /&gt;
    QString saveFileName(const QUrl &amp;amp;url);&lt;br /&gt;
signals:&lt;br /&gt;
    void finished();&lt;br /&gt;
private slots:&lt;br /&gt;
    void startNextDownload();&lt;br /&gt;
    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);&lt;br /&gt;
    void downloadFinished();&lt;br /&gt;
    void downloadReadyRead();&lt;br /&gt;
private:&lt;br /&gt;
    QNetworkAccessManager manager;&lt;br /&gt;
    QQueue&amp;lt;QUrl&amp;gt; downloadQueue;&lt;br /&gt;
    QNetworkReply *currentDownload;&lt;br /&gt;
    QFile output;&lt;br /&gt;
    QTime downloadTime;&lt;br /&gt;
    TextProgressBar progressBar;&lt;br /&gt;
    int downloadedCount;&lt;br /&gt;
    int totalCount;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;downloadmanager.h&amp;quot;&lt;br /&gt;
#include &amp;lt;QFileInfo&amp;gt;&lt;br /&gt;
#include &amp;lt;QNetworkRequest&amp;gt;&lt;br /&gt;
#include &amp;lt;QNetworkReply&amp;gt;&lt;br /&gt;
#include &amp;lt;QString&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QTimer&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
DownloadManager::DownloadManager(QObject *parent)&lt;br /&gt;
    : QObject(parent), downloadedCount(0), totalCount(0)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::append(const QStringList &amp;amp;urlList)&lt;br /&gt;
{&lt;br /&gt;
    foreach (QString url, urlList)&lt;br /&gt;
        append(QUrl::fromEncoded(url.toLocal8Bit()));&lt;br /&gt;
    if (downloadQueue.isEmpty())&lt;br /&gt;
        QTimer::singleShot(0, this, SIGNAL(finished()));&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::append(const QUrl &amp;amp;url)&lt;br /&gt;
{&lt;br /&gt;
    if (downloadQueue.isEmpty())&lt;br /&gt;
        QTimer::singleShot(0, this, SLOT(startNextDownload()));&lt;br /&gt;
    downloadQueue.enqueue(url);&lt;br /&gt;
    ++totalCount;&lt;br /&gt;
}&lt;br /&gt;
QString DownloadManager::saveFileName(const QUrl &amp;amp;url)&lt;br /&gt;
{&lt;br /&gt;
    QString path = url.path();&lt;br /&gt;
    QString basename = QFileInfo(path).fileName();&lt;br /&gt;
    if (basename.isEmpty())&lt;br /&gt;
        basename = &amp;quot;download&amp;quot;;&lt;br /&gt;
    if (QFile::exists(basename)) {&lt;br /&gt;
        // already exists, don&amp;quot;t overwrite&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        basename += &amp;quot;.&amp;quot;;&lt;br /&gt;
        while (QFile::exists(basename + QString::number(i)))&lt;br /&gt;
            ++i;&lt;br /&gt;
        basename += QString::number(i);&lt;br /&gt;
    }&lt;br /&gt;
    return basename;&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::startNextDownload()&lt;br /&gt;
{&lt;br /&gt;
    if (downloadQueue.isEmpty()) {&lt;br /&gt;
        printf(&amp;quot;%d/%d files downloaded successfully\n&amp;quot;, downloadedCount, totalCount);&lt;br /&gt;
        emit finished();&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    QUrl url = downloadQueue.dequeue();&lt;br /&gt;
    QString filename = saveFileName(url);&lt;br /&gt;
    output.setFileName(filename);&lt;br /&gt;
    if (!output.open(QIODevice::WriteOnly)) {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Problem opening save file &amp;quot;%s&amp;quot; for download &amp;quot;%s&amp;quot;: %s\n&amp;quot;,&lt;br /&gt;
                qPrintable(filename), url.toEncoded().constData(),&lt;br /&gt;
                qPrintable(output.errorString()));&lt;br /&gt;
        startNextDownload();&lt;br /&gt;
        return;                 // skip this download&lt;br /&gt;
    }&lt;br /&gt;
    QNetworkRequest request(url);&lt;br /&gt;
    currentDownload = manager.get(request);&lt;br /&gt;
    connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),&lt;br /&gt;
            SLOT(downloadProgress(qint64,qint64)));&lt;br /&gt;
    connect(currentDownload, SIGNAL(finished()),&lt;br /&gt;
            SLOT(downloadFinished()));&lt;br /&gt;
    connect(currentDownload, SIGNAL(readyRead()),&lt;br /&gt;
            SLOT(downloadReadyRead()));&lt;br /&gt;
    // prepare the output&lt;br /&gt;
    printf(&amp;quot;Downloading %s...\n&amp;quot;, url.toEncoded().constData());&lt;br /&gt;
    downloadTime.start();&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)&lt;br /&gt;
{&lt;br /&gt;
    progressBar.setStatus(bytesReceived, bytesTotal);&lt;br /&gt;
    // calculate the download speed&lt;br /&gt;
    double speed = bytesReceived * 1000.0 / downloadTime.elapsed();&lt;br /&gt;
    QString unit;&lt;br /&gt;
    if (speed &amp;lt; 1024) {&lt;br /&gt;
        unit = &amp;quot;bytes/sec&amp;quot;;&lt;br /&gt;
    } else if (speed &amp;lt; 1024*1024) {&lt;br /&gt;
        speed /= 1024;&lt;br /&gt;
        unit = &amp;quot;kB/s&amp;quot;;&lt;br /&gt;
    } else {&lt;br /&gt;
        speed /= 1024*1024;&lt;br /&gt;
        unit = &amp;quot;MB/s&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    progressBar.setMessage(QString::fromLatin1(&amp;quot;%1 %2&amp;quot;)&lt;br /&gt;
                           .arg(speed, 3, &amp;quot;f&amp;quot;, 1).arg(unit));&lt;br /&gt;
    progressBar.update();&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::downloadFinished()&lt;br /&gt;
{&lt;br /&gt;
    progressBar.clear();&lt;br /&gt;
    output.close();&lt;br /&gt;
    if (currentDownload-&amp;gt;error()) {&lt;br /&gt;
        // download failed&lt;br /&gt;
        fprintf(stderr, &amp;quot;Failed: %s\n&amp;quot;, qPrintable(currentDownload-&amp;gt;errorString()));&lt;br /&gt;
    } else {&lt;br /&gt;
        printf(&amp;quot;Succeeded.\n&amp;quot;);&lt;br /&gt;
        ++downloadedCount;&lt;br /&gt;
    }&lt;br /&gt;
    currentDownload-&amp;gt;deleteLater();&lt;br /&gt;
    startNextDownload();&lt;br /&gt;
}&lt;br /&gt;
void DownloadManager::downloadReadyRead()&lt;br /&gt;
{&lt;br /&gt;
    output.write(currentDownload-&amp;gt;readAll());&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QCoreApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
#include &amp;quot;downloadmanager.h&amp;quot;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
    QCoreApplication app(argc, argv);&lt;br /&gt;
    QStringList arguments = app.arguments();&lt;br /&gt;
    arguments.takeFirst();      // remove the first argument, which is the program&amp;quot;s name&lt;br /&gt;
    if (arguments.isEmpty()) {&lt;br /&gt;
        printf(&amp;quot;Qt Download example\n&amp;quot;&lt;br /&gt;
               &amp;quot;Usage: downloadmanager url1 [url2... urlN]\n&amp;quot;&lt;br /&gt;
               &amp;quot;\n&amp;quot;&lt;br /&gt;
               &amp;quot;Downloads the URLs passed in the command-line to the local directory\n&amp;quot;&lt;br /&gt;
               &amp;quot;If the target file already exists, a .0, .1, .2, etc. is appended to\n&amp;quot;&lt;br /&gt;
               &amp;quot;differentiate.\n&amp;quot;);&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
    DownloadManager manager;&lt;br /&gt;
    manager.append(arguments);&lt;br /&gt;
    QObject::connect(&amp;amp;manager, SIGNAL(finished()), &amp;amp;app, SLOT(quit()));&lt;br /&gt;
    app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==QNetworkAccessManager based google suggest==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef GOOGLESUGGEST_H&lt;br /&gt;
#define GOOGLESUGGEST_H&lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
#include &amp;lt;QNetworkAccessManager&amp;gt;&lt;br /&gt;
QT_BEGIN_NAMESPACE&lt;br /&gt;
class QLineEdit;&lt;br /&gt;
class QNetworkReply;&lt;br /&gt;
class QTimer;&lt;br /&gt;
class QTreeWidget;&lt;br /&gt;
QT_END_NAMESPACE&lt;br /&gt;
class GSuggestCompletion : public QObject&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    GSuggestCompletion(QLineEdit *parent = 0);&lt;br /&gt;
    ~GSuggestCompletion();&lt;br /&gt;
    bool eventFilter(QObject *obj, QEvent *ev);&lt;br /&gt;
    void showCompletion(const QStringList &amp;amp;choices, const QStringList &amp;amp;hits);&lt;br /&gt;
public slots:&lt;br /&gt;
    void doneCompletion();&lt;br /&gt;
    void preventSuggest();&lt;br /&gt;
    void autoSuggest();&lt;br /&gt;
    void handleNetworkData(QNetworkReply *networkReply);&lt;br /&gt;
private:&lt;br /&gt;
    QLineEdit *editor;&lt;br /&gt;
    QTreeWidget *popup;&lt;br /&gt;
    QTimer *timer;&lt;br /&gt;
    QNetworkAccessManager networkManager;&lt;br /&gt;
};&lt;br /&gt;
#endif // GOOGLESUGGEST_H&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtCore&amp;gt;&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;lt;QtNetwork&amp;gt;&lt;br /&gt;
#include &amp;quot;googlesuggest.h&amp;quot;&lt;br /&gt;
#define GSUGGEST_URL &amp;quot;http://google.com/complete/search?output=toolbar&amp;amp;q=%1&amp;quot;&lt;br /&gt;
GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), editor(parent)&lt;br /&gt;
{&lt;br /&gt;
    popup = new QTreeWidget;&lt;br /&gt;
    popup-&amp;gt;setColumnCount(2);&lt;br /&gt;
    popup-&amp;gt;setUniformRowHeights(true);&lt;br /&gt;
    popup-&amp;gt;setRootIsDecorated(false);&lt;br /&gt;
    popup-&amp;gt;setEditTriggers(QTreeWidget::NoEditTriggers);&lt;br /&gt;
    popup-&amp;gt;setSelectionBehavior(QTreeWidget::SelectRows);&lt;br /&gt;
    popup-&amp;gt;setFrameStyle(QFrame::Box | QFrame::Plain);&lt;br /&gt;
    popup-&amp;gt;setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);&lt;br /&gt;
    popup-&amp;gt;header()-&amp;gt;hide();&lt;br /&gt;
    popup-&amp;gt;installEventFilter(this);&lt;br /&gt;
    popup-&amp;gt;setMouseTracking(true);&lt;br /&gt;
    connect(popup, SIGNAL(itemClicked(QTreeWidgetItem*, int)),&lt;br /&gt;
            SLOT(doneCompletion()));&lt;br /&gt;
    popup-&amp;gt;setWindowFlags(Qt::Popup);&lt;br /&gt;
    popup-&amp;gt;setFocusPolicy(Qt::NoFocus);&lt;br /&gt;
    popup-&amp;gt;setFocusProxy(parent);&lt;br /&gt;
    timer = new QTimer(this);&lt;br /&gt;
    timer-&amp;gt;setSingleShot(true);&lt;br /&gt;
    timer-&amp;gt;setInterval(500);&lt;br /&gt;
    connect(timer, SIGNAL(timeout()), SLOT(autoSuggest()));&lt;br /&gt;
    connect(editor, SIGNAL(textEdited(QString)), timer, SLOT(start()));&lt;br /&gt;
    connect(&amp;amp;networkManager, SIGNAL(finished(QNetworkReply*)),&lt;br /&gt;
            this, SLOT(handleNetworkData(QNetworkReply*)));&lt;br /&gt;
}&lt;br /&gt;
GSuggestCompletion::~GSuggestCompletion()&lt;br /&gt;
{&lt;br /&gt;
    delete popup;&lt;br /&gt;
}&lt;br /&gt;
bool GSuggestCompletion::eventFilter(QObject *obj, QEvent *ev)&lt;br /&gt;
{&lt;br /&gt;
    if (obj != popup)&lt;br /&gt;
        return false;&lt;br /&gt;
    if (ev-&amp;gt;type() == QEvent::MouseButtonPress) {&lt;br /&gt;
        popup-&amp;gt;hide();&lt;br /&gt;
        editor-&amp;gt;setFocus();&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
    if (ev-&amp;gt;type() == QEvent::KeyPress) {&lt;br /&gt;
        bool consumed = false;&lt;br /&gt;
        int key = static_cast&amp;lt;QKeyEvent*&amp;gt;(ev)-&amp;gt;key();&lt;br /&gt;
        switch (key) {&lt;br /&gt;
        case Qt::Key_Enter:&lt;br /&gt;
        case Qt::Key_Return:&lt;br /&gt;
            doneCompletion();&lt;br /&gt;
            consumed = true;&lt;br /&gt;
        case Qt::Key_Escape:&lt;br /&gt;
            editor-&amp;gt;setFocus();&lt;br /&gt;
            popup-&amp;gt;hide();&lt;br /&gt;
            consumed = true;&lt;br /&gt;
        case Qt::Key_Up:&lt;br /&gt;
        case Qt::Key_Down:&lt;br /&gt;
        case Qt::Key_Home:&lt;br /&gt;
        case Qt::Key_End:&lt;br /&gt;
        case Qt::Key_PageUp:&lt;br /&gt;
        case Qt::Key_PageDown:&lt;br /&gt;
            break;&lt;br /&gt;
        default:&lt;br /&gt;
            editor-&amp;gt;setFocus();&lt;br /&gt;
            editor-&amp;gt;event(ev);&lt;br /&gt;
            popup-&amp;gt;hide();&lt;br /&gt;
            break;&lt;br /&gt;
        }&lt;br /&gt;
        return consumed;&lt;br /&gt;
    }&lt;br /&gt;
    return false;&lt;br /&gt;
}&lt;br /&gt;
void GSuggestCompletion::showCompletion(const QStringList &amp;amp;choices, const QStringList &amp;amp;hits)&lt;br /&gt;
{&lt;br /&gt;
    if (choices.isEmpty() || choices.count() != hits.count())&lt;br /&gt;
        return;&lt;br /&gt;
    const QPalette &amp;amp;pal = editor-&amp;gt;palette();&lt;br /&gt;
    QColor color = pal.color(QPalette::Disabled, QPalette::WindowText);&lt;br /&gt;
    popup-&amp;gt;setUpdatesEnabled(false);&lt;br /&gt;
    popup-&amp;gt;clear();&lt;br /&gt;
    for (int i = 0; i &amp;lt; choices.count(); ++i) {&lt;br /&gt;
        QTreeWidgetItem * item;&lt;br /&gt;
        item = new QTreeWidgetItem(popup);&lt;br /&gt;
        item-&amp;gt;setText(0, choices[i]);&lt;br /&gt;
        item-&amp;gt;setText(1, hits[i]);&lt;br /&gt;
        item-&amp;gt;setTextAlignment(1, Qt::AlignRight);&lt;br /&gt;
        item-&amp;gt;setTextColor(1, color);&lt;br /&gt;
    }&lt;br /&gt;
    popup-&amp;gt;setCurrentItem(popup-&amp;gt;topLevelItem(0));&lt;br /&gt;
    popup-&amp;gt;resizeColumnToContents(0);&lt;br /&gt;
    popup-&amp;gt;resizeColumnToContents(1);&lt;br /&gt;
    popup-&amp;gt;adjustSize();&lt;br /&gt;
    popup-&amp;gt;setUpdatesEnabled(true);&lt;br /&gt;
    int h = popup-&amp;gt;sizeHintForRow(0) * qMin(7, choices.count()) + 3;&lt;br /&gt;
    popup-&amp;gt;resize(popup-&amp;gt;width(), h);&lt;br /&gt;
    popup-&amp;gt;move(editor-&amp;gt;mapToGlobal(QPoint(0, editor-&amp;gt;height())));&lt;br /&gt;
    popup-&amp;gt;setFocus();&lt;br /&gt;
    popup-&amp;gt;show();&lt;br /&gt;
}&lt;br /&gt;
void GSuggestCompletion::doneCompletion()&lt;br /&gt;
{&lt;br /&gt;
    timer-&amp;gt;stop();&lt;br /&gt;
    popup-&amp;gt;hide();&lt;br /&gt;
    editor-&amp;gt;setFocus();&lt;br /&gt;
    QTreeWidgetItem *item = popup-&amp;gt;currentItem();&lt;br /&gt;
    if (item) {&lt;br /&gt;
        editor-&amp;gt;setText(item-&amp;gt;text(0));&lt;br /&gt;
        QKeyEvent *e;&lt;br /&gt;
        e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);&lt;br /&gt;
        QApplication::postEvent(editor, e);&lt;br /&gt;
        e = new QKeyEvent(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier);&lt;br /&gt;
        QApplication::postEvent(editor, e);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void GSuggestCompletion::preventSuggest()&lt;br /&gt;
{&lt;br /&gt;
    timer-&amp;gt;stop();&lt;br /&gt;
}&lt;br /&gt;
void GSuggestCompletion::autoSuggest()&lt;br /&gt;
{&lt;br /&gt;
    QString str = editor-&amp;gt;text();&lt;br /&gt;
    QString url = QString(GSUGGEST_URL).arg(str);&lt;br /&gt;
    networkManager.get(QNetworkRequest(QString(url)));&lt;br /&gt;
}&lt;br /&gt;
void GSuggestCompletion::handleNetworkData(QNetworkReply *networkReply)&lt;br /&gt;
{&lt;br /&gt;
    QUrl url = networkReply-&amp;gt;url();&lt;br /&gt;
    if (!networkReply-&amp;gt;error()) {&lt;br /&gt;
        QStringList choices;&lt;br /&gt;
        QStringList hits;&lt;br /&gt;
        QString response(networkReply-&amp;gt;readAll());&lt;br /&gt;
        QXmlStreamReader xml(response);&lt;br /&gt;
        while (!xml.atEnd()) {&lt;br /&gt;
            xml.readNext();&lt;br /&gt;
            if (xml.tokenType() == QXmlStreamReader::StartElement)&lt;br /&gt;
                if (xml.name() == &amp;quot;suggestion&amp;quot;) {&lt;br /&gt;
                    QStringRef str = xml.attributes().value(&amp;quot;data&amp;quot;);&lt;br /&gt;
                    choices &amp;lt;&amp;lt; str.toString();&lt;br /&gt;
                }&lt;br /&gt;
            if (xml.tokenType() == QXmlStreamReader::StartElement)&lt;br /&gt;
                if (xml.name() == &amp;quot;num_queries&amp;quot;) {&lt;br /&gt;
                    QStringRef str = xml.attributes().value(&amp;quot;int&amp;quot;);&lt;br /&gt;
                    hits &amp;lt;&amp;lt; str.toString();&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
        showCompletion(choices, hits);&lt;br /&gt;
    }&lt;br /&gt;
    networkReply-&amp;gt;deleteLater();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef SEARCHBOX_H&lt;br /&gt;
#define SEARCHBOX_H&lt;br /&gt;
#include &amp;lt;QLineEdit&amp;gt;&lt;br /&gt;
class GSuggestCompletion;&lt;br /&gt;
class SearchBox: public QLineEdit&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    SearchBox(QWidget *parent = 0);&lt;br /&gt;
protected slots:&lt;br /&gt;
    void doSearch();&lt;br /&gt;
private:&lt;br /&gt;
    GSuggestCompletion *completer;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
#endif // SEARCHBOX_H&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QDesktopServices&amp;gt;&lt;br /&gt;
#include &amp;lt;QUrl&amp;gt;&lt;br /&gt;
#include &amp;quot;searchbox.h&amp;quot;&lt;br /&gt;
#include &amp;quot;googlesuggest.h&amp;quot;&lt;br /&gt;
#define GSEARCH_URL &amp;quot;http://www.google.com/search?q=%1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SearchBox::SearchBox(QWidget *parent): QLineEdit(parent)&lt;br /&gt;
{&lt;br /&gt;
    completer = new GSuggestCompletion(this);&lt;br /&gt;
    connect(this, SIGNAL(returnPressed()), SLOT(doSearch()));&lt;br /&gt;
    setWindowTitle(&amp;quot;Search with Google&amp;quot;);&lt;br /&gt;
    adjustSize();&lt;br /&gt;
    resize(400, height());&lt;br /&gt;
    setFocus();&lt;br /&gt;
}&lt;br /&gt;
void SearchBox::doSearch()&lt;br /&gt;
{&lt;br /&gt;
    completer-&amp;gt;preventSuggest();&lt;br /&gt;
    QString url = QString(GSEARCH_URL).arg(text());&lt;br /&gt;
    QDesktopServices::openUrl(QUrl(url));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;quot;searchbox.h&amp;quot;&lt;br /&gt;
int main(int argc, char * argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    SearchBox *searchEdit = new SearchBox;&lt;br /&gt;
    searchEdit-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>