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

#include <QGCFileDownload.h>

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

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)
 

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
void finished(bool success, const QString &localPath, const QString &errorMessage)

Example QML usage:

id: downloader
autoDecompress: true
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)
}

Definition at line 62 of file QGCFileDownload.h.

Member Function Documentation

◆ autoDecompressChanged

void QGCFileDownload::autoDecompressChanged ( bool  autoDecompress)
signal

Emitted when auto-decompress setting changes.

◆ 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().

Referenced by QGCCachedFileDownload::cancel().

◆ 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.

◆ errorStringChanged

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

Emitted when error string changes.

◆ expectedHashChanged

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

Emitted when expected hash setting changes.

◆ 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().

◆ localPathChanged

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

Emitted when local path changes.

Referenced by start().

◆ outputPathChanged

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

Emitted when output path setting changes.

◆ progressChanged

void QGCFileDownload::progressChanged ( qreal  progress)
signal

Emitted when download progress changes.

◆ runningChanged

void QGCFileDownload::runningChanged ( bool  running)
signal

Emitted when running state changes.

◆ 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(), 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(), QGCFileHelper::ensureParentExists(), QGCNetworkHelper::ignoreSslErrorsIfNeeded(), QGCFileHelper::isLocalPath(), localPathChanged(), QGCFileHelper::toLocalPath(), totalBytesChanged(), and urlChanged().

◆ stateChanged

void QGCFileDownload::stateChanged ( State  state)
signal

Emitted when state changes.

◆ totalBytesChanged

void QGCFileDownload::totalBytesChanged ( qint64  totalBytes)
signal

Emitted when total bytes changes.

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: