FileDownloader: Do not assume existence of QQmlData

QQmlData::wasDeleted returns a sensible result, even when the QQmlData
has not been created (for instance because the object was not
instantiated by the QML engine). Checking the result of
QQmlData::get is counterproductive, as FileDownloader objects are for
instance created by ContentLibraryMaterialsModel::fetchBundleIcons,
without going through the QML engine.

Moreover, try to log some information about why we ended up with a
network error.

Task-number: QDS-9687
Change-Id: Icf7fba94a8a0552305ac39f2caa32426e58972a0
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Fabian Kosmale
2023-04-20 14:51:21 +02:00
parent 35582ffcb5
commit 50aa8fedd2

View File

@@ -258,18 +258,16 @@ void FileDownloader::doProbeUrl()
QNetworkReply::connect(reply,
&QNetworkReply::errorOccurred,
this,
[this](QNetworkReply::NetworkError) {
QQmlData *data = QQmlData::get(this, false);
if (!data) {
qDebug() << Q_FUNC_INFO << "FileDownloader is nullptr.";
return;
}
[this](QNetworkReply::NetworkError code) {
if (QQmlData::wasDeleted(this)) {
qDebug() << Q_FUNC_INFO << "FileDownloader was deleted.";
return;
}
qDebug() << Q_FUNC_INFO << "Network error:" << code
<< qobject_cast<QNetworkReply *>(sender())->errorString();
m_available = false;
emit availableChanged();
});