diff options
author | Michal Klocek <michal.klocek@qt.io> | 2019-09-18 10:53:38 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2019-09-26 10:28:20 +0000 |
commit | e77ec61b7ba1fb71b397ef358036b5057a0cb39b (patch) | |
tree | d92613a60773af306b0c78fbae2622bedacdf8ea | |
parent | e31acc86e991d6f83bd56eebb7371914fc9ca5ac (diff) |
Unify shared context initialization
Setting shared context on core application object should
be done before core application is initialised. This is handled
correctly in widgets part but not in qml part. Unify
our shared context creation and call WebEngine::initialize()
before QCoreaApplication is created. Context has to be set shared
before first window's QPlatformOpenGLContext is created and not
before window itself is created as documentation claimed.
Keep the older code running, but print the warning.
Update one test to test new initialization order, but keep the others
to check if they still works.
[ChangeLog] WebEngine::initialize() has to be called before
QCoreApplication is created.
Task-number: QTBUG-76391
Change-Id: Iff938493a4d21f360110136192daedb6199584c1
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | examples/webengine/customdialogs/main.cpp | 3 | ||||
-rw-r--r-- | examples/webengine/minimal/main.cpp | 3 | ||||
-rw-r--r-- | examples/webengine/quicknanobrowser/main.cpp | 3 | ||||
-rw-r--r-- | examples/webengine/recipebrowser/main.cpp | 3 | ||||
-rw-r--r-- | examples/webengine/webengineaction/main.cpp | 4 | ||||
-rw-r--r-- | src/core/api/qtwebenginecoreglobal.cpp | 2 | ||||
-rw-r--r-- | src/core/content_browser_client_qt.cpp | 2 | ||||
-rw-r--r-- | src/webengine/api/qtwebengineglobal.cpp | 15 | ||||
-rw-r--r-- | tests/auto/quick/dialogs/tst_dialogs.cpp | 5 | ||||
-rw-r--r-- | tests/auto/quick/shared/util.h | 12 |
10 files changed, 37 insertions, 15 deletions
diff --git a/examples/webengine/customdialogs/main.cpp b/examples/webengine/customdialogs/main.cpp index 82a3eca63..5aad8affb 100644 --- a/examples/webengine/customdialogs/main.cpp +++ b/examples/webengine/customdialogs/main.cpp @@ -67,9 +67,10 @@ int main(int argc, char *argv[]) { QCoreApplication::setOrganizationName("QtExamples"); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - Application app(argc, argv); QtWebEngine::initialize(); + Application app(argc, argv); + QQmlApplicationEngine engine; Server *server = new Server(&engine); diff --git a/examples/webengine/minimal/main.cpp b/examples/webengine/minimal/main.cpp index 9db6ea6aa..348517ee0 100644 --- a/examples/webengine/minimal/main.cpp +++ b/examples/webengine/minimal/main.cpp @@ -56,9 +56,8 @@ int main(int argc, char *argv[]) { QCoreApplication::setOrganizationName("QtExamples"); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication app(argc, argv); - QtWebEngine::initialize(); + QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); diff --git a/examples/webengine/quicknanobrowser/main.cpp b/examples/webengine/quicknanobrowser/main.cpp index 8d032f5d8..d09abba3c 100644 --- a/examples/webengine/quicknanobrowser/main.cpp +++ b/examples/webengine/quicknanobrowser/main.cpp @@ -80,11 +80,10 @@ int main(int argc, char **argv) { QCoreApplication::setOrganizationName("QtExamples"); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QtWebEngine::initialize(); Application app(argc, argv); - QtWebEngine::initialize(); - QQmlApplicationEngine appEngine; Utils utils; appEngine.rootContext()->setContextProperty("utils", &utils); diff --git a/examples/webengine/recipebrowser/main.cpp b/examples/webengine/recipebrowser/main.cpp index 6e6d69804..e61b9e0f5 100644 --- a/examples/webengine/recipebrowser/main.cpp +++ b/examples/webengine/recipebrowser/main.cpp @@ -58,9 +58,10 @@ int main(int argc, char *argv[]) { QCoreApplication::setOrganizationName("QtExamples"); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication app(argc, argv); QtWebEngine::initialize(); + QGuiApplication app(argc, argv); + QQuickStyle::setStyle(QStringLiteral("Material")); QQmlApplicationEngine engine; diff --git a/examples/webengine/webengineaction/main.cpp b/examples/webengine/webengineaction/main.cpp index ce723a99b..f2dec9655 100644 --- a/examples/webengine/webengineaction/main.cpp +++ b/examples/webengine/webengineaction/main.cpp @@ -56,10 +56,10 @@ int main(int argc, char *argv[]) { QCoreApplication::setOrganizationName("QtExamples"); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QGuiApplication app(argc, argv); - QtWebEngine::initialize(); + QGuiApplication app(argc, argv); + QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); diff --git a/src/core/api/qtwebenginecoreglobal.cpp b/src/core/api/qtwebenginecoreglobal.cpp index 25d0bd3be..3c7fc54a1 100644 --- a/src/core/api/qtwebenginecoreglobal.cpp +++ b/src/core/api/qtwebenginecoreglobal.cpp @@ -108,7 +108,7 @@ Q_WEBENGINECORE_PRIVATE_EXPORT void initialize() QCoreApplication *app = QCoreApplication::instance(); if (!app) { - qFatal("QtWebEngine::initialize() must be called after the construction of the application object."); + qFatal("QtWebEngine::initialize() but no core application instance."); return; } diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 16945020b..04a8fc363 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -235,7 +235,7 @@ void ShareGroupQtQuick::AboutToAddFirstContext() // This currently has to be setup by ::main in all applications using QQuickWebEngineView with delegated rendering. QOpenGLContext *shareContext = qt_gl_global_share_context(); if (!shareContext) { - qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QtWebEngine::initialize() in your main() function."); + qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QtWebEngine::initialize() in your main() function before QCoreApplication is created."); } m_shareContextQtQuick = new QtShareGLContext(shareContext); #endif diff --git a/src/webengine/api/qtwebengineglobal.cpp b/src/webengine/api/qtwebengineglobal.cpp index a11618dba..4346832c9 100644 --- a/src/webengine/api/qtwebengineglobal.cpp +++ b/src/webengine/api/qtwebengineglobal.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qtwebengineglobal.h" +#include <QCoreApplication> namespace QtWebEngineCore { @@ -62,8 +63,8 @@ namespace QtWebEngine { /*! \fn QtWebEngine::initialize() - Sets up an OpenGL Context that can be shared between threads. This has to be done after - QGuiApplication is created, but before a Qt Quick window is created. + Sets up an OpenGL Context that can be shared between threads. This has to be done before + QGuiApplication is created and before window's QPlatformOpenGLContext is created. This has the same effect as setting the Qt::AA_ShareOpenGLContexts attribute with QCoreApplication::setAttribute before constructing @@ -71,7 +72,15 @@ namespace QtWebEngine { */ void initialize() { - QtWebEngineCore::initialize(); + QCoreApplication *app = QCoreApplication::instance(); + if (app) { + qWarning("QtWebEngine::initialize() called with QCoreApplication object already created and should be call before. "\ + "This is depreciated and may fail in the future."); + QtWebEngineCore::initialize(); + return; + } + // call initialize the same way as widgets do + qAddPreRoutine(QtWebEngineCore::initialize); } } // namespace QtWebEngine diff --git a/tests/auto/quick/dialogs/tst_dialogs.cpp b/tests/auto/quick/dialogs/tst_dialogs.cpp index eee6b2bb6..82ea3be37 100644 --- a/tests/auto/quick/dialogs/tst_dialogs.cpp +++ b/tests/auto/quick/dialogs/tst_dialogs.cpp @@ -28,6 +28,7 @@ #include "testhandler.h" #include "server.h" +#include "util.h" #include <QtWebEngine/private/qquickwebenginedialogrequests_p.h> #include <QtWebEngine/private/qquickwebenginecontextmenurequest_p.h> #include <QQuickWebEngineProfile> @@ -43,6 +44,7 @@ class tst_Dialogs : public QObject { public: tst_Dialogs(){} + private slots: void initTestCase(); void init(); @@ -64,7 +66,6 @@ private: void tst_Dialogs::initTestCase() { - QtWebEngine::initialize(); QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true); qmlRegisterType<TestHandler>("io.qt.tester", 1, 0, "TestHandler"); m_engine.reset(new QQmlApplicationEngine()); @@ -230,5 +231,5 @@ void tst_Dialogs::javaScriptDialogRequested() } #include "tst_dialogs.moc" -QTEST_MAIN(tst_Dialogs) +W_QTEST_MAIN(tst_Dialogs) diff --git a/tests/auto/quick/shared/util.h b/tests/auto/quick/shared/util.h index c2e7d3e19..bc5ae445b 100644 --- a/tests/auto/quick/shared/util.h +++ b/tests/auto/quick/shared/util.h @@ -36,6 +36,7 @@ #include <QtTest/QtTest> #include <QtWebEngine/private/qquickwebengineview_p.h> #include <QtWebEngine/private/qquickwebengineloadrequest_p.h> +#include <QGuiApplication> #if !defined(TESTS_SOURCE_DIR) #define TESTS_SOURCE_DIR "" @@ -182,4 +183,15 @@ inline QString activeElementId(QQuickWebEngineView *webEngineView) return arguments.at(1).toString(); } +#define W_QTEST_MAIN(TestObject) \ +int main(int argc, char *argv[]) \ +{ \ + QtWebEngine::initialize(); \ + QGuiApplication app(argc, argv); \ + app.setAttribute(Qt::AA_Use96Dpi, true); \ + TestObject tc; \ + QTEST_SET_MAIN_SOURCE_PATH \ + return QTest::qExec(&tc, argc, argv); \ +} #endif /* UTIL_H */ + |