diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 748dc287ef..3650c495f2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -7389,7 +7389,10 @@ void Application::updateDisplayMode() { getApplicationCompositor().setDisplayPlugin(newDisplayPlugin); _displayPlugin = newDisplayPlugin; connect(_displayPlugin.get(), &DisplayPlugin::presented, this, &Application::onPresent); - offscreenUi->getDesktop()->setProperty("repositionLocked", wasRepositionLocked); + auto desktop = offscreenUi->getDesktop(); + if (desktop) { + desktop->setProperty("repositionLocked", wasRepositionLocked); + } } bool isHmd = _displayPlugin->isHmd(); diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index c9341fd3d9..515215a8d3 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -169,12 +169,14 @@ void LoginDialog::openUrl(const QString& url) const { auto offscreenUi = DependencyManager::get(); if (tablet->getToolbarMode()) { - auto browser = offscreenUi->load("Browser.qml"); - browser->setProperty("url", url); + offscreenUi->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) { + newObject->setProperty("url", url); + }); } else { if (!hmd->getShouldShowTablet() && !qApp->isHMDMode()) { - auto browser = offscreenUi->load("Browser.qml"); - browser->setProperty("url", url); + offscreenUi->load("Browser.qml", [=](QQmlContext* context, QObject* newObject) { + newObject->setProperty("url", url); + }); } else { tablet->gotoWebScreen(url); } diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index c1120f1775..b4a07ecd47 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -554,20 +554,19 @@ void OffscreenUi::createDesktop(const QUrl& url) { getSurfaceContext()->setContextProperty("DebugQML", QVariant(false)); #endif - _desktop = dynamic_cast(load(url)); - Q_ASSERT(_desktop); - getSurfaceContext()->setContextProperty("desktop", _desktop); + load(url, [=](QQmlContext* context, QObject* newObject) { + _desktop = static_cast(newObject); + getSurfaceContext()->setContextProperty("desktop", _desktop); + _toolWindow = _desktop->findChild("ToolWindow"); - _toolWindow = _desktop->findChild("ToolWindow"); + _vrMenu = new VrMenu(this); + for (const auto& menuInitializer : _queuedMenuInitializers) { + menuInitializer(_vrMenu); + } - _vrMenu = new VrMenu(this); - for (const auto& menuInitializer : _queuedMenuInitializers) { - menuInitializer(_vrMenu); - } - - new KeyboardFocusHack(); - - connect(_desktop, SIGNAL(showDesktop()), this, SIGNAL(showDesktop())); + new KeyboardFocusHack(); + connect(_desktop, SIGNAL(showDesktop()), this, SIGNAL(showDesktop())); + }); } QQuickItem* OffscreenUi::getDesktop() { diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index 84466f41b0..d29dc7a0f9 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -639,7 +639,7 @@ void OffscreenQmlSurface::setBaseUrl(const QUrl& baseUrl) { _qmlContext->setBaseUrl(baseUrl); } -QObject* OffscreenQmlSurface::load(const QUrl& qmlSource, bool createNewContext, std::function f) { +void OffscreenQmlSurface::load(const QUrl& qmlSource, bool createNewContext, std::function f) { if (QThread::currentThread() != thread()) { qCWarning(uiLogging) << "Called load on a non-surface thread"; } @@ -662,32 +662,32 @@ QObject* OffscreenQmlSurface::load(const QUrl& qmlSource, bool createNewContext, [this, qmlComponent, targetContext, f](QQmlComponent::Status) { finishQmlLoad(qmlComponent, targetContext, f); }); - return nullptr; + return; } - return finishQmlLoad(qmlComponent, targetContext, f); + finishQmlLoad(qmlComponent, targetContext, f); } -QObject* OffscreenQmlSurface::loadInNewContext(const QUrl& qmlSource, std::function f) { - return load(qmlSource, true, f); +void OffscreenQmlSurface::loadInNewContext(const QUrl& qmlSource, std::function f) { + load(qmlSource, true, f); } -QObject* OffscreenQmlSurface::load(const QUrl& qmlSource, std::function f) { - return load(qmlSource, false, f); +void OffscreenQmlSurface::load(const QUrl& qmlSource, std::function f) { + load(qmlSource, false, f); } void OffscreenQmlSurface::clearCache() { _qmlContext->engine()->clearComponentCache(); } -QObject* OffscreenQmlSurface::finishQmlLoad(QQmlComponent* qmlComponent, QQmlContext* qmlContext, std::function f) { +void OffscreenQmlSurface::finishQmlLoad(QQmlComponent* qmlComponent, QQmlContext* qmlContext, std::function f) { disconnect(qmlComponent, &QQmlComponent::statusChanged, this, 0); if (qmlComponent->isError()) { for (const auto& error : qmlComponent->errors()) { qCWarning(uiLogging) << error.url() << error.line() << error; } qmlComponent->deleteLater(); - return nullptr; + return; } @@ -700,7 +700,7 @@ QObject* OffscreenQmlSurface::finishQmlLoad(QQmlComponent* qmlComponent, QQmlCon qFatal("Unable to finish loading QML root"); } qmlComponent->deleteLater(); - return nullptr; + return; } qmlContext->engine()->setObjectOwnership(this, QQmlEngine::CppOwnership); @@ -726,19 +726,19 @@ QObject* OffscreenQmlSurface::finishQmlLoad(QQmlComponent* qmlComponent, QQmlCon } // If we already have a root, just set a couple of flags and the ancestry - if (_rootItem) { + if (newItem && _rootItem) { // Allow child windows to be destroyed from JS QQmlEngine::setObjectOwnership(newObject, QQmlEngine::JavaScriptOwnership); newObject->setParent(_rootItem); if (newItem) { newItem->setParentItem(_rootItem); } - return newObject; + return; } if (!newItem) { qFatal("Could not load object as root item"); - return nullptr; + return; } connect(newItem, SIGNAL(sendToScript(QVariant)), this, SIGNAL(fromQml(QVariant))); @@ -747,7 +747,6 @@ QObject* OffscreenQmlSurface::finishQmlLoad(QQmlComponent* qmlComponent, QQmlCon _rootItem = newItem; _rootItem->setParentItem(_quickWindow->contentItem()); _rootItem->setSize(_quickWindow->renderTargetSize()); - return _rootItem; } void OffscreenQmlSurface::updateQuick() { diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.h b/libraries/ui/src/ui/OffscreenQmlSurface.h index 3b53f6a185..7da929723c 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.h +++ b/libraries/ui/src/ui/OffscreenQmlSurface.h @@ -50,10 +50,10 @@ public: void resize(const QSize& size, bool forceResize = false); QSize size() const; - Q_INVOKABLE QObject* load(const QUrl& qmlSource, bool createNewContext, std::function f = [](QQmlContext*, QObject*) {}); - Q_INVOKABLE QObject* loadInNewContext(const QUrl& qmlSource, std::function f = [](QQmlContext*, QObject*) {}); - Q_INVOKABLE QObject* load(const QUrl& qmlSource, std::function f = [](QQmlContext*, QObject*) {}); - Q_INVOKABLE QObject* load(const QString& qmlSourceFile, std::function f = [](QQmlContext*, QObject*) {}) { + Q_INVOKABLE void load(const QUrl& qmlSource, bool createNewContext, std::function f = [](QQmlContext*, QObject*) {}); + Q_INVOKABLE void loadInNewContext(const QUrl& qmlSource, std::function f = [](QQmlContext*, QObject*) {}); + Q_INVOKABLE void load(const QUrl& qmlSource, std::function f = [](QQmlContext*, QObject*) {}); + Q_INVOKABLE void load(const QString& qmlSourceFile, std::function f = [](QQmlContext*, QObject*) {}) { return load(QUrl(qmlSourceFile), f); } void clearCache(); @@ -120,7 +120,7 @@ protected: private: static QOpenGLContext* getSharedContext(); - QObject* finishQmlLoad(QQmlComponent* qmlComponent, QQmlContext* qmlContext, std::function f); + void finishQmlLoad(QQmlComponent* qmlComponent, QQmlContext* qmlContext, std::function f); QPointF mapWindowToUi(const QPointF& sourcePosition, QObject* sourceObject); void setupFbo(); bool allowNewFrame(uint8_t fps);