QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCFileDownload Class Reference

File download with progress, decompression, and hash verification. More...

#include <QGCFileDownload.h>

+ Inheritance diagram for QGCFileDownload:
+ Collaboration diagram for QGCFileDownload:

Public Types

enum class  State {
  Idle , Downloading , Decompressing , Verifying ,
  Completed , Failed , Cancelled
}
 Current download progress (0.0 to 1.0) More...
 

Public Slots

bool start (const QString &remoteUrl)
 
bool start (const QString &remoteUrl, const QGCNetworkHelper::RequestConfig &config)
 
void cancel ()
 Cancel current download.
 

Signals

void progressChanged (qreal progress)
 Emitted when download progress changes.
 
void runningChanged (bool running)
 Emitted when running state changes.
 
void errorStringChanged (const QString &errorString)
 Emitted when error string changes.
 
void urlChanged (const QUrl &url)
 Emitted when URL changes.
 
void localPathChanged (const QString &localPath)
 Emitted when local path changes.
 
void totalBytesChanged (qint64 totalBytes)
 Emitted when total bytes changes.
 
void bytesReceivedChanged (qint64 bytesReceived)
 Emitted when bytes received changes.
 
void autoDecompressChanged (bool autoDecompress)
 Emitted when auto-decompress setting changes.
 
void outputPathChanged (const QString &outputPath)
 Emitted when output path setting changes.
 
void expectedHashChanged (const QString &expectedHash)
 Emitted when expected hash setting changes.
 
void stateChanged (State state)
 Emitted when state changes.
 
void finished (bool success, const QString &localPath, const QString &errorMessage)
 
void downloadProgress (qint64 bytesReceived, qint64 totalBytes)
 Emitted during download with byte counts.
 
void decompressionProgress (qreal progress)
 Emitted during decompression (0.0 to 1.0)
 

Public Member Functions

 QGCFileDownload (QObject *parent=nullptr)
 
 ~QGCFileDownload () override
 
qreal progress () const
 
bool isRunning () const
 
QString errorString () const
 
QUrl url () const
 
QString localPath () const
 
qint64 totalBytes () const
 
qint64 bytesReceived () const
 
bool autoDecompress () const
 
QString outputPath () const
 
QString expectedHash () const
 
State state () const
 
bool lastResultFromCache () const
 
void setAutoDecompress (bool enabled)
 
void setOutputPath (const QString &path)
 
void setExpectedHash (const QString &hash)
 
void setCache (QAbstractNetworkCache *cache)
 Set network cache for downloads.
 
void setTimeout (int timeoutMs)
 Set request timeout in milliseconds.
 
QNetworkAccessManager * networkManager () const
 Get the network access manager (for advanced configuration)
 

Detailed Description

File download with progress, decompression, and hash verification.

Features:

  • HTTP/HTTPS and local file:// downloads
  • Automatic redirect handling
  • Progress reporting with cancellation
  • Optional auto-decompression of .gz/.xz/.zst/.bz2 files
  • Optional SHA-256 hash verification
  • Streaming to file (memory-efficient)
  • QML-compatible properties and signals

Example C++ usage:

auto *download = new QGCFileDownload(this);
connect(download, &QGCFileDownload::finished, this,
[](bool success, const QString &localPath, const QString &error) {
if (success) {
qDebug() << "Downloaded to:" << localPath;
} else {
qWarning() << "Download failed:" << error;
}
});
download->start("https://example.com/file.zip");
Error error
File download with progress, decompression, and hash verification.
void finished(bool success, const QString &localPath, const QString &errorMessage)
QString localPath() const

Example QML usage:

id: downloader
onProgressChanged: progressBar.value = progress
onFinished: (success, path, error) => {
if (!success) console.log("Error:", error)
}
}
Button {
text: downloader.running ? "Cancel" : "Download"
onClicked: downloader.running ? downloader.cancel()
: downloader.start(urlField.text)
}
bool autoDecompress() const
void cancel()
Cancel current download.
qreal progress() const

Definition at line 60 of file QGCFileDownload.h.

Member Enumeration Documentation

◆ State

enum class QGCFileDownload::State
strong

Current download progress (0.0 to 1.0)

Whether a download is currently in progress Error message from last failed download (empty if successful) Remote URL being downloaded Local file path where download is saved Total bytes to download (-1 if unknown) Bytes downloaded so far Whether to auto-decompress compressed files after download Custom output path (empty = auto-generate in temp directory) Expected SHA-256 hash for verification (empty = skip verification) Download state

Enumerator
Idle 

No download in progress.

Downloading 

Actively downloading.

Decompressing 

Decompressing downloaded file.

Verifying 

Verifying file hash.

Completed 

Download completed successfully.

Failed 

Download failed.

Cancelled 

Download was cancelled.

Definition at line 97 of file QGCFileDownload.h.

Constructor & Destructor Documentation

◆ QGCFileDownload()

QGCFileDownload::QGCFileDownload ( QObject *  parent = nullptr)
explicit

Definition at line 14 of file QGCFileDownload.cc.

◆ ~QGCFileDownload()

QGCFileDownload::~QGCFileDownload ( )
override

Definition at line 21 of file QGCFileDownload.cc.

References cancel().

Member Function Documentation

◆ autoDecompress()

bool QGCFileDownload::autoDecompress ( ) const
inline

Definition at line 122 of file QGCFileDownload.h.

◆ autoDecompressChanged

void QGCFileDownload::autoDecompressChanged ( bool  autoDecompress)
signal

Emitted when auto-decompress setting changes.

Referenced by setAutoDecompress().

◆ bytesReceived()

qint64 QGCFileDownload::bytesReceived ( ) const
inline

Definition at line 121 of file QGCFileDownload.h.

◆ bytesReceivedChanged

void QGCFileDownload::bytesReceivedChanged ( qint64  bytesReceived)
signal

Emitted when bytes received changes.

Referenced by start().

◆ cancel

void QGCFileDownload::cancel ( )
slot

Cancel current download.

Definition at line 175 of file QGCFileDownload.cc.

References QGCCompressionJob::cancel(), Cancelled, Completed, Failed, Idle, and QGCCompressionJob::isRunning().

Referenced by QGCCachedFileDownload::cancel(), and ~QGCFileDownload().

◆ decompressionProgress

void QGCFileDownload::decompressionProgress ( qreal  progress)
signal

Emitted during decompression (0.0 to 1.0)

◆ downloadProgress

void QGCFileDownload::downloadProgress ( qint64  bytesReceived,
qint64  totalBytes 
)
signal

Emitted during download with byte counts.

Referenced by QGCCachedFileDownload::QGCCachedFileDownload(), and QGCCachedFileDownload::QGCCachedFileDownload().

◆ errorString()

QString QGCFileDownload::errorString ( ) const
inline

Definition at line 117 of file QGCFileDownload.h.

Referenced by APMAirframeComponentController::loadParameters().

◆ errorStringChanged

void QGCFileDownload::errorStringChanged ( const QString &  errorString)
signal

Emitted when error string changes.

◆ expectedHash()

QString QGCFileDownload::expectedHash ( ) const
inline

Definition at line 124 of file QGCFileDownload.h.

◆ expectedHashChanged

void QGCFileDownload::expectedHashChanged ( const QString &  expectedHash)
signal

Emitted when expected hash setting changes.

Referenced by setExpectedHash().

◆ finished

void QGCFileDownload::finished ( bool  success,
const QString &  localPath,
const QString &  errorMessage 
)
signal

Emitted when download completes (success or failure)

Parameters
successtrue if download succeeded
localPathPath to downloaded file (empty on failure)
errorMessageError message (empty on success)

Referenced by FirmwarePlugin::checkIfIsLatestStable(), APMAirframeComponentController::loadParameters(), QGCCachedFileDownload::QGCCachedFileDownload(), and QGCCachedFileDownload::QGCCachedFileDownload().

◆ isRunning()

bool QGCFileDownload::isRunning ( ) const
inline

Definition at line 113 of file QGCFileDownload.h.

References Decompressing, Downloading, and Verifying.

Referenced by start().

◆ lastResultFromCache()

bool QGCFileDownload::lastResultFromCache ( ) const
inline

Definition at line 126 of file QGCFileDownload.h.

◆ localPath()

QString QGCFileDownload::localPath ( ) const
inline

Definition at line 119 of file QGCFileDownload.h.

◆ localPathChanged

void QGCFileDownload::localPathChanged ( const QString &  localPath)
signal

Emitted when local path changes.

Referenced by start().

◆ networkManager()

QNetworkAccessManager * QGCFileDownload::networkManager ( ) const
inline

Get the network access manager (for advanced configuration)

Definition at line 140 of file QGCFileDownload.h.

◆ outputPath()

QString QGCFileDownload::outputPath ( ) const
inline

Definition at line 123 of file QGCFileDownload.h.

◆ outputPathChanged

void QGCFileDownload::outputPathChanged ( const QString &  outputPath)
signal

Emitted when output path setting changes.

Referenced by setOutputPath().

◆ progress()

qreal QGCFileDownload::progress ( ) const
inline

Definition at line 112 of file QGCFileDownload.h.

◆ progressChanged

void QGCFileDownload::progressChanged ( qreal  progress)
signal

Emitted when download progress changes.

◆ runningChanged

void QGCFileDownload::runningChanged ( bool  running)
signal

Emitted when running state changes.

◆ setAutoDecompress()

void QGCFileDownload::setAutoDecompress ( bool  enabled)

Definition at line 31 of file QGCFileDownload.cc.

References autoDecompressChanged().

◆ setCache()

void QGCFileDownload::setCache ( QAbstractNetworkCache *  cache)

Set network cache for downloads.

Definition at line 55 of file QGCFileDownload.cc.

◆ setExpectedHash()

void QGCFileDownload::setExpectedHash ( const QString &  hash)

Definition at line 47 of file QGCFileDownload.cc.

References expectedHashChanged().

◆ setOutputPath()

void QGCFileDownload::setOutputPath ( const QString &  path)

Definition at line 39 of file QGCFileDownload.cc.

References outputPathChanged().

◆ setTimeout()

void QGCFileDownload::setTimeout ( int  timeoutMs)

Set request timeout in milliseconds.

Definition at line 60 of file QGCFileDownload.cc.

◆ start [1/2]

bool QGCFileDownload::start ( const QString &  remoteUrl)
slot

Start downloading a file

Parameters
remoteUrlURL or file path to download
Returns
true if download started successfully

Definition at line 69 of file QGCFileDownload.cc.

References QGCNetworkHelper::RequestConfig::allowRedirects, start(), and QGCNetworkHelper::RequestConfig::timeoutMs.

Referenced by FirmwarePlugin::checkIfIsLatestStable(), APMAirframeComponentController::loadParameters(), and start().

◆ start [2/2]

bool QGCFileDownload::start ( const QString &  remoteUrl,
const QGCNetworkHelper::RequestConfig config 
)
slot

Start downloading a file with custom request configuration

Parameters
remoteUrlURL or file path to download
configRequest configuration (timeout, headers, etc.)
Returns
true if download started successfully

Definition at line 77 of file QGCFileDownload.cc.

References bytesReceivedChanged(), QGCNetworkHelper::createRequest(), Downloading, QGCFileHelper::ensureParentExists(), QGCNetworkHelper::ignoreSslErrorsIfNeeded(), QGCFileHelper::isLocalPath(), isRunning(), localPathChanged(), QGCFileHelper::toLocalPath(), totalBytesChanged(), url(), and urlChanged().

◆ state()

State QGCFileDownload::state ( ) const
inline

Definition at line 125 of file QGCFileDownload.h.

◆ stateChanged

void QGCFileDownload::stateChanged ( State  state)
signal

Emitted when state changes.

◆ totalBytes()

qint64 QGCFileDownload::totalBytes ( ) const
inline

Definition at line 120 of file QGCFileDownload.h.

◆ totalBytesChanged

void QGCFileDownload::totalBytesChanged ( qint64  totalBytes)
signal

Emitted when total bytes changes.

Referenced by start().

◆ url()

QUrl QGCFileDownload::url ( ) const
inline

Definition at line 118 of file QGCFileDownload.h.

Referenced by start().

◆ urlChanged

void QGCFileDownload::urlChanged ( const QUrl &  url)
signal

Emitted when URL changes.

Referenced by start().


The documentation for this class was generated from the following files: