diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-12-08 08:34:12 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2021-01-27 10:14:46 +0100 |
commit | 2e7a10fa88f363a2cdd3ab1b567f8e39c10bdba3 (patch) | |
tree | 1b72bf177b7d4b00f77a86f769750e4ecf8997eb /src | |
parent | 074c6c068a80687f756314cecc092a48436c4712 (diff) |
Do the pre-initialization steps after the plugin paths are set
Since initialize() is called before the creation of the application
then we need to delay the actual implementation until the paths are
set. Therefore a prehook is used for the application object so that
these can be done before the application finishes initalizing. For
static builds we call this function right away, thus requiring the
need for the QtWebView::initialize() function to still exist.
Change-Id: Ic4633cd1e96c39bc12f475fdd22c56646ea7ca10
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
(cherry picked from commit 8e82991875c82916785823ba01a02614b04369de)
Diffstat (limited to 'src')
-rw-r--r-- | src/webview/qtwebviewfunctions.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/webview/qtwebviewfunctions.cpp b/src/webview/qtwebviewfunctions.cpp index b9b2d89..c1c3d6b 100644 --- a/src/webview/qtwebviewfunctions.cpp +++ b/src/webview/qtwebviewfunctions.cpp @@ -38,6 +38,7 @@ #include "qwebviewfactory_p.h" #include "qwebviewplugin_p.h" +#include <QtCore/qcoreapplication.h> QT_BEGIN_NAMESPACE @@ -48,26 +49,42 @@ QT_BEGIN_NAMESPACE \inheaderfile QtWebView */ +// This is a separate function so we can be sure that in non-static cases it can be registered +// as a pre hook for QCoreApplication, ensuring this is called after the plugin paths have +// been set to their defaults. For static builds then this will be called explicitly when +// QtWebView::initialize() is called by the application + +static void initializeImpl() +{ + if (QWebViewFactory::requiresExtraInitializationSteps()) { + // There might be plugins available, but their dependencies might not be met, + // so make sure we have a valid plugin before using it. + // Note: A warning will be printed later if we're unable to load the plugin. + QWebViewPlugin *plugin = QWebViewFactory::getPlugin(); + if (plugin) + plugin->prepare(); + } +} + +#ifndef QT_STATIC +Q_COREAPP_STARTUP_FUNCTION(initializeImpl); +#endif + /*! \fn void QtWebView::initialize() \keyword qtwebview-initialize This function initializes resources or sets options that are required by the different back-ends. - \note The \c initialize() function needs to be called immediately after the QGuiApplication + \note The \c initialize() function needs to be called immediately before the QGuiApplication instance is created. */ void QtWebView::initialize() { - if (QWebViewFactory::requiresExtraInitializationSteps()) { - // There might be plugins available, but their dependencies might not be met, - // so make sure we have a valid plugin before using it. - // Note: A warning will be printed later if we're unable to load the plugin. - QWebViewPlugin *plugin = QWebViewFactory::getPlugin(); - if (plugin) - plugin->prepare(); - } +#ifdef QT_STATIC + initializeImpl(); +#endif } QT_END_NAMESPACE |