diff options
Diffstat (limited to 'src/qml/qml/qqmlapplicationengine.cpp')
-rw-r--r-- | src/qml/qml/qqmlapplicationengine.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlapplicationengine.cpp b/src/qml/qml/qqmlapplicationengine.cpp index 6ee03b39e5..a2976b59c3 100644 --- a/src/qml/qml/qqmlapplicationengine.cpp +++ b/src/qml/qml/qqmlapplicationengine.cpp @@ -81,7 +81,8 @@ void QQmlApplicationEnginePrivate::init() else delete qtTranslator; #endif - new QQmlFileSelector(q,q); + auto *selector = new QQmlFileSelector(q,q); + selector->setExtraSelectors(extraFileSelectors); QCoreApplication::instance()->setProperty("__qml_using_qqmlapplicationengine", QVariant(true)); } @@ -94,7 +95,7 @@ void QQmlApplicationEnginePrivate::_q_loadTranslations() Q_Q(QQmlApplicationEngine); QScopedPointer<QTranslator> translator(new QTranslator); - if (!uiLanguage.isEmpty()) { + if (!uiLanguage.value().isEmpty()) { QLocale locale(uiLanguage); if (translator->load(locale, QLatin1String("qml"), QLatin1String("_"), translationsDirectory, QLatin1String(".qm"))) { if (activeTranslator) @@ -113,6 +114,11 @@ void QQmlApplicationEnginePrivate::startLoad(const QUrl &url, const QByteArray & { Q_Q(QQmlApplicationEngine); + if (!isInitialized) { + init(); + isInitialized = true; + } + if (url.scheme() == QLatin1String("file") || url.scheme() == QLatin1String("qrc")) { QFileInfo fi(QQmlFile::urlToLocalFileOrQrc(url)); translationsDirectory = fi.path() + QLatin1String("/i18n"); @@ -225,8 +231,6 @@ void QQmlApplicationEnginePrivate::finishLoad(QQmlComponent *c) QQmlApplicationEngine::QQmlApplicationEngine(QObject *parent) : QQmlEngine(*(new QQmlApplicationEnginePrivate(this)), parent) { - Q_D(QQmlApplicationEngine); - d->init(); QJSEnginePrivate::addToDebugServer(this); } @@ -310,6 +314,26 @@ void QQmlApplicationEngine::setInitialProperties(const QVariantMap &initialPrope } /*! + Sets the \a extraFileSelectors to be passed to the internal QQmlFileSelector + used for resolving URLs to local files. The \a extraFileSelectors are applied + when the first QML file is loaded. Setting them afterwards has no effect. + + \sa QQmlFileSelector + \sa QFileSelector::setExtraSelectors + \since 6.0 +*/ +void QQmlApplicationEngine::setExtraFileSelectors(const QStringList &extraFileSelectors) +{ + Q_D(QQmlApplicationEngine); + if (d->isInitialized) { + qWarning() << "QQmlApplicationEngine::setExtraFileSelectors()" + << "called after loading QML files. This has no effect."; + } else { + d->extraFileSelectors = extraFileSelectors; + } +} + +/*! Loads the QML given in \a data. The object tree defined by \a data is instantiated immediately. |