diff options
author | Robert Griebl <robert.griebl@qt.io> | 2022-04-26 02:55:31 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2022-04-27 22:52:16 +0000 |
commit | 26883bdab67e28d96fd148f3b2304f4d7325ab66 (patch) | |
tree | 8a4f1ef9809911baf43f511599b091e374240292 | |
parent | 71e0532fc13fc8ee8f3919b81c8004daa939a4a8 (diff) |
Better debug output when failing to load resources
Change-Id: I30bbd0d62d2e9ed07ca425424cbcb1c3d64e72f1
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
-rw-r--r-- | src/common-lib/utilities.cpp | 31 | ||||
-rw-r--r-- | src/common-lib/utilities.h | 2 | ||||
-rw-r--r-- | src/main-lib/main.cpp | 7 | ||||
-rw-r--r-- | src/manager-lib/qmlinprocessruntime.cpp | 8 | ||||
-rw-r--r-- | src/tools/launcher-qml/launcher-qml.cpp | 15 |
5 files changed, 46 insertions, 17 deletions
diff --git a/src/common-lib/utilities.cpp b/src/common-lib/utilities.cpp index 54b4c654..9ccf85ff 100644 --- a/src/common-lib/utilities.cpp +++ b/src/common-lib/utilities.cpp @@ -304,18 +304,33 @@ QString translateFromMap(const QMap<QString, QString> &languageToName, const QSt } } -bool loadResource(const QString &resource) +void loadResource(const QString &resource) Q_DECL_NOEXCEPT_EXPR(false) { QString afp = QDir().absoluteFilePath(resource); - - bool ok = false; - ok = ok || (QLibrary::isLibrary(resource) && QLibrary(afp).load()); - ok = ok || QResource::registerResource(resource); - ok = ok || QLibrary(afp).load(); + QStringList errors; + QString debugSuffix; #if defined(Q_OS_WINDOWS) - ok = ok || QLibrary(afp % u'd').load(); + debugSuffix = qSL("d"); +#elif defined(Q_OS_MACOS) + debugSuffix = qSL("_debug"); #endif - return ok; + + if (QResource::registerResource(resource)) + return; + errors.append(qL1S("Cannot load as Qt Resource file")); + + QLibrary lib(afp); + if (lib.load()) + return; + errors.append(lib.errorString()); + + if (!debugSuffix.isEmpty()) { + QLibrary libd(afp % debugSuffix); + if (libd.load()) + return; + errors.append(libd.errorString()); + } + throw Exception("Failed to load resource %1:\n * %2").arg(resource).arg(errors.join(qL1S("\n * "))); } void closeAndClearFileDescriptors(QVector<int> &fdList) diff --git a/src/common-lib/utilities.h b/src/common-lib/utilities.h index de979daa..65c5943a 100644 --- a/src/common-lib/utilities.h +++ b/src/common-lib/utilities.h @@ -138,7 +138,7 @@ QVector<T *> loadPlugins(const char *type, const QStringList &files) Q_DECL_NOEX } // Load a Qt resource, either in the form of a resource file or a plugin -bool loadResource(const QString &resource); +void loadResource(const QString &resource) Q_DECL_NOEXCEPT_EXPR(false); // Qt6 removed v_cast, but the "replacement" QVariant::Private::get is const only template <typename T> T *qt6_v_cast(QVariant::Private *vp) diff --git a/src/main-lib/main.cpp b/src/main-lib/main.cpp index c4dc4069..93137b8e 100644 --- a/src/main-lib/main.cpp +++ b/src/main-lib/main.cpp @@ -318,8 +318,11 @@ QQmlApplicationEngine *Main::qmlEngine() const void Main::registerResources(const QStringList &resources) const { for (const QString &resource: resources) { - if (!loadResource(resource)) - qCWarning(LogSystem) << "Cannot register resource:" << resource; + try { + loadResource(resource); + } catch (const Exception &e) { + qCWarning(LogSystem).noquote() << e.errorString(); + } } } diff --git a/src/manager-lib/qmlinprocessruntime.cpp b/src/manager-lib/qmlinprocessruntime.cpp index 9777d257..7b41de17 100644 --- a/src/manager-lib/qmlinprocessruntime.cpp +++ b/src/manager-lib/qmlinprocessruntime.cpp @@ -43,6 +43,7 @@ #include "qmlinprocessapplicationmanagerwindow.h" #include "inprocesssurfaceitem.h" #include "logging.h" +#include "exception.h" #include "application.h" #include "qmlinprocessruntime.h" #include "qmlinprocessapplicationinterface.h" @@ -263,8 +264,11 @@ void QmlInProcessRuntime::loadResources(const QStringList &resources, const QStr const QString path = QFileInfo(resource).isRelative() ? baseDir + resource : resource; static QStringList cache; if (!cache.contains(path)) { - if (!loadResource(path)) - qCWarning(LogQmlRuntime) << "Cannot register resource:" << path; + try { + loadResource(path); + } catch (const Exception &e) { + qCWarning(LogQmlRuntime).noquote() << e.errorString(); + } cache.append(path); } } diff --git a/src/tools/launcher-qml/launcher-qml.cpp b/src/tools/launcher-qml/launcher-qml.cpp index 601c4307..3baddb6f 100644 --- a/src/tools/launcher-qml/launcher-qml.cpp +++ b/src/tools/launcher-qml/launcher-qml.cpp @@ -213,8 +213,12 @@ Controller::Controller(LauncherMain *launcher, bool quickLaunched, const QPair<Q const QStringList resources = variantToStringList(m_configuration.value(qSL("resources"))); for (const QString &resource: resources) { const QString path = QFileInfo(resource).isRelative() ? launcher->baseDir() + resource : resource; - if (!loadResource(path)) - qCWarning(LogSystem) << "Cannot register resource:" << path; + + try { + loadResource(path); + } catch (const Exception &e) { + qCWarning(LogSystem).noquote() << e.errorString(); + } } QString absolutePluginPath; @@ -386,8 +390,11 @@ void Controller::startApplication(const QString &baseDir, const QString &qmlFile : qdbus_cast<QVariantList>(resVar); for (const QVariant &resource : resources) { - if (!loadResource(resource.toString())) - qCWarning(LogQmlRuntime) << "Cannot register resource:" << resource.toString(); + try { + loadResource(resource.toString()); + } catch (const Exception &e) { + qCWarning(LogSystem).noquote() << e.errorString(); + } } const QUrl qmlFileUrl = filePathToUrl(qmlFile, baseDir); |