From beb595266df7c23f50f6a1aa663dd353cb4468c1 Mon Sep 17 00:00:00 2001
From: Alexander Ivash <elderorb@gmail.com>
Date: Thu, 15 Feb 2018 21:45:35 +0300
Subject: [PATCH] fix 4x 'fromQml' slots execution

note: per discussion with Austion & Seth, TabletRoot should be the only entity sending 'sendToScript' signals to C++
---
 libraries/qml/src/qml/OffscreenSurface.cpp  | 2 +-
 libraries/ui/src/ui/OffscreenQmlSurface.cpp | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/libraries/qml/src/qml/OffscreenSurface.cpp b/libraries/qml/src/qml/OffscreenSurface.cpp
index 87fc8a3025..a84f3feb4d 100644
--- a/libraries/qml/src/qml/OffscreenSurface.cpp
+++ b/libraries/qml/src/qml/OffscreenSurface.cpp
@@ -331,9 +331,9 @@ void OffscreenSurface::finishQmlLoad(QQmlComponent* qmlComponent,
     qmlComponent->deleteLater();
 
     onItemCreated(qmlContext, newItem);
-    connect(newItem, SIGNAL(sendToScript(QVariant)), this, SIGNAL(fromQml(QVariant)));
 
     if (!rootCreated) {
+        connect(newItem, SIGNAL(sendToScript(QVariant)), this, SIGNAL(fromQml(QVariant)));
         onRootCreated();
         emit rootItemCreated(newItem);
         // Call this callback after rootitem is set, otherwise VrMenu wont work
diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp
index ea34f3de76..749a60a578 100644
--- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp
+++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp
@@ -305,7 +305,6 @@ void OffscreenQmlSurface::onItemCreated(QQmlContext* qmlContext, QQuickItem* new
         qmlContext->setContextProperty("eventBridgeWrapper", new EventBridgeWrapper(eventBridge, qmlContext));
     }
 
-    connect(newItem, SIGNAL(sendToScript(QVariant)), this, SIGNAL(fromQml(QVariant)));
 }
 
 void OffscreenQmlSurface::onRootCreated() {