Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9316027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:30:58+00:00 2026-06-19T02:30:58+00:00

For three days now I try to come up with a workable code to

  • 0

For three days now I try to come up with a workable code to simply download a file from an Url, but I had my fair share of problems so far and now I am at a point where I can’t see the error.

First of all, my code:

main.cpp

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    w.downloadArchive(QString("https://bitbucket.org/BattleClinic/evemon/downloads/EVEMon-binaries-1.8.1.4016.zip"), QCoreApplication::applicationDirPath(), QString("evemon.zip"));

    return a.exec();
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFile>
#include <QFileInfo>
#include <QNetworkAccessManager>
#include <QNetworkReply>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    bool downloadArchive(QString archiveUrl, QString saveToPath, QString archiveName);

private slots:
    void downloadReadyRead();
    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
    void downloadFinished();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

QNetworkAccessManager manager;
QFile *file;
QNetworkReply *reply;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->downloadLabel->hide();
    ui->downloadProgressBar->hide();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::downloadReadyRead()
{
    if(file)
    {
        file->write(reply->readAll());
    }
}

void MainWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
    ui->downloadProgressBar->setMaximum(bytesTotal);
    ui->downloadProgressBar->setValue(bytesReceived);
}

void MainWindow::downloadFinished()
{
    downloadReadyRead();
    file->flush();
    file->close();

    if(reply->error())
    {
        QMessageBox::information(this, "Download failed", tr("Failed: %1").arg(reply->errorString()));
    }

    reply->deleteLater();
    reply = NULL;
    delete file;
    file = NULL;

    ui->downloadLabel->hide();
    ui->downloadProgressBar->hide();
}

bool MainWindow::downloadArchive(QString archiveUrl, QString saveToPath, QString archiveName)
{
    QUrl url(archiveUrl);

    if(archiveName.count() <= 0)
    {
        return false;
    }

    if(QFile::exists(saveToPath + "/" + archiveName))
    {
        QFile::remove(saveToPath + "/" + archiveName);
    }

    file = new QFile(saveToPath + "/" + archiveName);

    if(!file->open(QIODevice::WriteOnly))
    {
        delete file;
        file = NULL;
        return false;
    }

    reply = manager.get(QNetworkRequest(url));

    connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
    connect(reply, SIGNAL(readyRead()), this, SLOT(downloadReadyRead()));
    connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));

    ui->downloadLabel->setText(QString("Downloading %1...").arg(archiveName));
    ui->downloadLabel->show();
    ui->downloadProgressBar->show();

    return true;
}

Downloader.pro

QT       += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Downloader
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

In mainwindow.cpp I’m checking for an error and print it to a MessageBox, in case there is one. The first error I had with the current code in the reply was “Unable to init SSL Context”, because I’m requesting data from a https-site. I googled a while and found the solution to be two files called “libeay32.dll” and “ssleay32.dll” I had to copy to the executable’s directory.

There are now no more errors within the reply (at least the MessageBox doesn’t show up)….however, after the downloadFinished Function was executed, the downloaded file has a size of 0 kb, which makes me think, their wasn’t at all a download happening.

I skipped the “if(reply->error())” statement and showed the MessageBox no matter what….I got an: “Unknown Error”. Should an “Unknown Error” not set the “if(reply->error())” statement to true?

There is no problem with permissions either….I tried it as Admin….so no problem at creating the file itself.
Can anyone help me to get that code working?
Do I miss any dlls or an #include?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:30:59+00:00Added an answer on June 19, 2026 at 2:30 am

    Make sure that it works for a non-ssl file. Then to add ssl support, try following the directions in the answers to this question:

    Qt SSL support missing

    Also try using qDebug in your code instead of the QMessageBox most of the time. It makes adding debugging lines easier, and it won’t interrupt your code or fill your screen with QMessageBoxes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried for three days now and gotten nowhere on this.... I absolutely
Three days i was trying to figure out how to read file using relative
I have tried for a few days now to figure this out but i
I've been on this now for three days, and I've tried pretty much every
A few days ago I asked a question about reading from file until the
For almost three days now I have been trying to get the boost libs
I have been fiddling with a few lines of code for two days now
I spent the last three days working on the collection _ select form helper
Hi everyone I am in my last three days before I present my final
i have three columns for Date In, Date Out, Total Days. If in Date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.