19 m_ppb =
new QProgressBar;
20 m_ptxt =
new QLineEdit;
21 m_pcmd =
new QPushButton(tr(
"&Go"));
23 QString strDownloadLink =
"http://qt-book.com/pic.jpg";
24 m_ptxt->setText(strDownloadLink);
26 connect(m_pcmd, SIGNAL(clicked()), SLOT(slotGo()));
27 connect(m_pdl, SIGNAL(downloadProgress(qint64, qint64)),
28 this, SLOT(slotDownloadProgress(qint64, qint64))
30 connect(m_pdl, SIGNAL(done(
const QUrl&,
const QByteArray&)),
31 this, SLOT(slotDone(
const QUrl&,
const QByteArray&))
34 QGridLayout* pLayout =
new QGridLayout;
35 pLayout->addWidget(m_ptxt, 0, 0);
36 pLayout->addWidget(m_pcmd, 0, 1);
37 pLayout->addWidget(m_ppb, 1, 0, 1, 1);
42 void DownloaderGui::slotGo()
44 m_pdl->
download(QUrl(m_ptxt->text()));
48 void DownloaderGui::slotDownloadProgress(qint64 nReceived, qint64 nTotal)
54 m_ppb->setValue(100 * nReceived / nTotal);
58 void DownloaderGui::slotDone(
const QUrl& url,
const QByteArray& ba)
61 QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)
62 +
"/" + url.path().section(
'/', -1);
63 QFile file(strFileName);
64 if (file.open(QIODevice::WriteOnly)) {
68 if (strFileName.endsWith(
".jpg")
69 || strFileName.endsWith(
".png")
77 void DownloaderGui::showPic(
const QString& strFileName)
79 QPixmap pix(strFileName);
80 pix = pix.scaled(pix.size() / 2,
81 Qt::IgnoreAspectRatio,
82 Qt::SmoothTransformation
84 QLabel* plbl =
new QLabel;
86 plbl->setFixedSize(pix.size());
91 void DownloaderGui::slotError()
93 QMessageBox::critical(0,
95 tr(
"An error while download is occured")
void download(const QUrl &)
DownloaderGui(QWidget *pwgt=0)