diff --git a/src/native/QmlNet/QmlNet/qml/NetJsValue.cpp b/src/native/QmlNet/QmlNet/qml/NetJsValue.cpp index f24e8681..8af1c871 100644 --- a/src/native/QmlNet/QmlNet/qml/NetJsValue.cpp +++ b/src/native/QmlNet/QmlNet/qml/NetJsValue.cpp @@ -39,7 +39,7 @@ QSharedPointer NetJSValue::call(const QSharedPointer if(parameters != nullptr) { for(int x = 0; x < parameters->count(); x++) { QSharedPointer netVariant = parameters->get(x); - jsValueList.append(netVariant->toQJSValue(_jsValue.engine())); + jsValueList.append(netVariant->toQJSValue()); } } @@ -62,7 +62,7 @@ void NetJSValue::setProperty(const QString& propertyName, const QSharedPointertoQJSValue(_jsValue.engine()); + value = variant->toQJSValue(); } _jsValue.setProperty(propertyName, value); } @@ -71,7 +71,7 @@ void NetJSValue::setItemAtIndex(quint32 arrayIndex, const QSharedPointertoQJSValue(_jsValue.engine()); + value = variant->toQJSValue(); } _jsValue.setProperty(arrayIndex, value); } diff --git a/src/native/QmlNet/QmlNet/qml/NetVariant.cpp b/src/native/QmlNet/QmlNet/qml/NetVariant.cpp index e65953f0..960db94d 100644 --- a/src/native/QmlNet/QmlNet/qml/NetVariant.cpp +++ b/src/native/QmlNet/QmlNet/qml/NetVariant.cpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace { @@ -238,18 +239,18 @@ QSharedPointer NetVariant::fromQJSValue(const QJSValue& qJsValue) return result; } -QJSValue NetVariant::toQJSValue(QJSEngine* jsEngine) const +QJSValue NetVariant::toQJSValue() const { switch(getVariantType()) { case NetVariantTypeEnum_Object: { NetValue* netValue = NetValue::forInstance(getNetReference()); - return jsEngine->newQObject(netValue); + return sharedQmlEngine()->newQObject(netValue); } case NetVariantTypeEnum_JSValue: { return getJsValue()->getJsValue(); } default: { - return jsEngine->toScriptValue(toQVariant()); + return sharedQmlEngine()->toScriptValue(toQVariant()); } } } diff --git a/src/native/QmlNet/QmlNet/qml/NetVariant.h b/src/native/QmlNet/QmlNet/qml/NetVariant.h index 3dd99794..8ef1ead1 100644 --- a/src/native/QmlNet/QmlNet/qml/NetVariant.h +++ b/src/native/QmlNet/QmlNet/qml/NetVariant.h @@ -40,7 +40,7 @@ public: QSharedPointer getJsValue() const; void clear(); static QSharedPointer fromQJSValue(const QJSValue& qJsValue); - QJSValue toQJSValue(QJSEngine* jsEngine) const; + QJSValue toQJSValue() const; static void fromQVariant(const QVariant* variant, const QSharedPointer& destination); static QSharedPointer fromQVariant(const QVariant* variant); QVariant toQVariant() const; diff --git a/src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.cpp b/src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.cpp index 4a86fddd..f697e46b 100644 --- a/src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.cpp +++ b/src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.cpp @@ -5,6 +5,17 @@ #include #include +static QQmlApplicationEngine* sharedQmlEngineValue = nullptr; + +QQmlApplicationEngine* sharedQmlEngine() +{ + if(sharedQmlEngineValue == nullptr) { + qWarning("An attempt was made to get a shared application engine, but it is NULL. .NET needs to know about it. Returning null, but expect segfaults."); + return nullptr; + } + return sharedQmlEngineValue; +} + static int netValueTypeNumber = 0; #define NETVALUETYPE_CASE(N) \ @@ -28,6 +39,8 @@ Q_DECL_EXPORT QQmlApplicationEngineContainer* qqmlapplicationengine_create(QQmlA ownsEngine = true; } + sharedQmlEngineValue = engine; + JsNetObject* netObject = new JsNetObject(); engine->rootContext()->setContextProperty("Net", netObject); diff --git a/src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.h b/src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.h index 4ae3e63e..4a214a2e 100644 --- a/src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.h +++ b/src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.h @@ -5,6 +5,8 @@ #include #include +QQmlApplicationEngine* sharedQmlEngine(); + struct QQmlApplicationEngineContainer { QQmlApplicationEngine* qmlEngine; JsNetObject* netObject;