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 9007153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:36:40+00:00 2026-06-16T01:36:40+00:00

I have this QT script using webkit. I can download files no problem but

  • 0

I have this QT script using webkit. I can download files no problem but I can’t get the progress bar moving in the file dialog. I think the network reply has already been sent before I call the progress dialog as there is a delay from clicking the download link and then then qDebug() << "Left click - download!"; being echo’s out into console. How can I intercept the netwrok reply before it has finished and the unsupportedContent() method is called?

EDIT:
I could strip it out and use reply = manager.get(QNetworkRequest(url)); but I don’t actually know the URL it could be any link the user clicks, there is no predefined URL?

void MainWindow::unsupportedContent(QNetworkReply *reply) {

    qDebug() << "Left click - download!";
    qDebug() << "Bytes to download: " << reply->bytesAvailable();

    QString str = reply->rawHeader("Content-Disposition");

    QString end = str.mid(21);
    end.chop(1);

    qDebug() << "File name: " << end;
    qDebug() << "File type: " << reply->rawHeader("Content-Type");
    qDebug() << "File size (bytes): " << reply->bytesAvailable();
    QString defaultFileName = QFileInfo(end).fileName();
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), defaultFileName);
    if (fileName.isEmpty()) return;

    file = new QFile(fileName);
    if(!file->open(QIODevice::WriteOnly))
    {
        QMessageBox::information(this, "Downloader",
            tr("Unable to save the file %1: %2.")
            .arg(fileName).arg(file->errorString()));
        delete file;
        file = NULL;
        return;
    }

    downloadRequestAborted = false;

    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)));
        connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
        progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
        //downloadButton->setEnabled(false);
        progressDialog->exec();


    //QFile file(fileName);
    //file.open( QIODevice::WriteOnly );
    //file.write(reply->read(reply->bytesAvailable()));
    //file.close();
}

void MainWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
    qDebug() << bytesReceived << bytesTotal;
    if(downloadRequestAborted)
        return;
    progressDialog->setMaximum(bytesTotal);
    progressDialog->setValue(bytesReceived);
}

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

void MainWindow::downloadFinished()
{
    qDebug() << "Download finished!";
    if(downloadRequestAborted)
    {
        if(file)
        {
            file->close();
            file->remove();
            delete file;
            file = NULL;
        }
        reply->deleteLater();
        progressDialog->hide();
        //downloadButton->setEnabled(true);
        return;
    }

    downloadReadyRead();
    progressDialog->hide();
    //downloadButton->setEnabled(true);
    file->flush();
    file->close();

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

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

void MainWindow::cancelDownload()
{
    downloadRequestAborted = true;
    reply->abort();
    progressDialog->hide();
    //downloadButton->setEnabled(true);
}
  • 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-16T01:36:42+00:00Added an answer on June 16, 2026 at 1:36 am

    The above method was working the whole time the problem was the bytes it was receiving was so small you could not tell it had downloaded at all, once I attempted to download a larger file the bytes being downloaded were adequately displayed 🙂

    Here is the method I ended up with that could receive a request and save it disk.

    void MainWindow::unsupportedContent(QNetworkReply *reply) {
    
        QString str = reply->rawHeader("Content-Disposition");
    
        QString end = str.mid(21);
        end.chop(1);
    
        QString defaultFileName = QFileInfo(end).fileName();
        QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), defaultFileName);
        if (fileName.isEmpty()) return;
    
        file = new QFile(fileName);
        if(!file->open(QIODevice::WriteOnly))
        {
            QMessageBox::information(this, "Downloader",
                tr("Unable to save the file %1: %2.")
                .arg(fileName).arg(file->errorString()));
            delete file;
            file = NULL;
            return;
        }
    
        downloadRequestAborted = false;
        if(!reply->isFinished()){
        connect(reply, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64)));
    
        connect(progressDialog, SIGNAL(canceled()), SLOT(cancelDownload()));
        progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
        progressDialog->exec();
        //return;
        }
    
        if(downloadRequestAborted)
        {
            if(file)
            {
                file->close();
                file->remove();
                delete file;
                file = NULL;
            }
            reply->abort();
            reply->deleteLater();
            progressDialog->hide();
            return;
        }
    
        file->write(reply->read(reply->bytesAvailable()));
        file->flush();
        file->close();
        file = NULL;
    
        if(file == NULL){
            isDownload = true;
            fileURL = fileName;
        systray->showMessage("CytoViewer v1.0", "Download finished - Click to open", QSystemTrayIcon::NoIcon, 10000);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file hosting site that's using this script MFHS . I want
I currently have this script where users (using a form where they can upload
I have this content script that downloads some binary data using XHR, which is
i have only ftp credentials in which i am using this script $r=mysqldump $dbuser
I have this code to show a map using the Virtual Earth API: <script
I have this script that run to fix my menu bar to the browser
I have this fragment that demonstrates the problem: <html> <head> <title>height query demo</title> <script
Alrighty so below I have this script doing exactly what I want; I'm using
OK, i have this jQuery script using ajax to load a response from a
I have this script and need to be able to call the $play variable

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.