diff options
authorCorentin Jabot <>2015-12-16 10:18:30 +0100
committerJoerg Bornemann <>2016-04-28 12:39:27 +0000
commita8564cc6fb40fe6a9c3f5f6f37392a628aa5b685 (patch)
parentf77cd97cacd1603fdca0c3fda405d351a1ccda93 (diff)
Never call QtWebEngine::initialize from DllMain
On windows, calling QtWebEngine::initialize from DllMain may crash, depending on what QPA backend is used. We make sure to only add a qAddPreRoutine initializing QtWebEngine if there is no instance of QCoreApplication. By doing so, we support linking to QtWebEngineWidget from a plugin, while still initializing the WebEngine automatically when linked to the main application binary. Task-number: QTBUG-46720 Reviewed-by: Jocelyn Turcotte (Woboq GmbH) <> (cherry picked from commit 6a8d99ab00ace2084820547572dc05ac8ad2bc5a) Change-Id: Id3b2c1e21e01808cef124f8ece6b247b1ba613cb Reviewed-by: Michael BrĂ¼ning <>
2 files changed, 16 insertions, 6 deletions
diff --git a/src/core/api/qtwebenginecoreglobal.cpp b/src/core/api/qtwebenginecoreglobal.cpp
index 0e857d7d9..e60e6139e 100644
--- a/src/core/api/qtwebenginecoreglobal.cpp
+++ b/src/core/api/qtwebenginecoreglobal.cpp
@@ -75,6 +75,11 @@ QWEBENGINE_PRIVATE_EXPORT void initialize()
qFatal("QtWebEngine::initialize() must be called after the construction of the application object.");
+ // Bail out silently if the user did not construct a QGuiApplication.
+ if (!qobject_cast<QGuiApplication *>(app))
+ return;
if (app->thread() != QThread::currentThread()) {
qFatal("QtWebEngine::initialize() must be called from the Qt gui thread.");
diff --git a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp
index 263376e45..5ebb8b546 100644
--- a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp
+++ b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp
@@ -36,7 +36,7 @@
#include "qtwebenginewidgetsglobal.h"
-#include <QGuiApplication>
+#include <QCoreApplication>
namespace QtWebEngineCore
@@ -46,13 +46,18 @@ namespace QtWebEngineCore
static void initialize()
- // Bail out silently if the user did not construct a QGuiApplication.
- if (!qobject_cast<QGuiApplication *>(QCoreApplication::instance()))
+ //On window/ANGLE, calling QtWebEngine::initialize from DllMain will result in a crash.
+ //To ensure it doesn't, we check that when loading the library
+ //QCoreApplication is not yet instantiated, ensuring the call will be deferred
+#if defined(Q_OS_WIN)
+ if (QCoreApplication::instance()
+ && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
- QtWebEngineCore::initialize();
+ }
+ qAddPreRoutine(QtWebEngineCore::initialize);