mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-21 06:45:32 -06:00
Don't use deprecated prop to get QJSEngine.
This commit is contained in:
parent
efddc4fa24
commit
cc2b2cfb2c
5 changed files with 23 additions and 7 deletions
|
|
@ -39,7 +39,7 @@ QSharedPointer<NetVariant> NetJSValue::call(const QSharedPointer<NetVariantList>
|
|||
if(parameters != nullptr) {
|
||||
for(int x = 0; x < parameters->count(); x++) {
|
||||
QSharedPointer<NetVariant> 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 QSharedPointer<N
|
|||
{
|
||||
QJSValue value = QJSValue::NullValue;
|
||||
if(variant != nullptr) {
|
||||
value = variant->toQJSValue(_jsValue.engine());
|
||||
value = variant->toQJSValue();
|
||||
}
|
||||
_jsValue.setProperty(propertyName, value);
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ void NetJSValue::setItemAtIndex(quint32 arrayIndex, const QSharedPointer<NetVari
|
|||
{
|
||||
QJSValue value = QJSValue::NullValue;
|
||||
if(variant != nullptr) {
|
||||
value = variant->toQJSValue(_jsValue.engine());
|
||||
value = variant->toQJSValue();
|
||||
}
|
||||
_jsValue.setProperty(arrayIndex, value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QJSEngine>
|
||||
#include <QmlNet/qml/QQmlApplicationEngine.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
@ -238,18 +239,18 @@ QSharedPointer<NetVariant> 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<QVariant>(toQVariant());
|
||||
return sharedQmlEngine()->toScriptValue<QVariant>(toQVariant());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public:
|
|||
QSharedPointer<NetJSValue> getJsValue() const;
|
||||
void clear();
|
||||
static QSharedPointer<NetVariant> fromQJSValue(const QJSValue& qJsValue);
|
||||
QJSValue toQJSValue(QJSEngine* jsEngine) const;
|
||||
QJSValue toQJSValue() const;
|
||||
static void fromQVariant(const QVariant* variant, const QSharedPointer<NetVariant>& destination);
|
||||
static QSharedPointer<NetVariant> fromQVariant(const QVariant* variant);
|
||||
QVariant toQVariant() const;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,17 @@
|
|||
#include <QmlNet/qml/JsNetObject.h>
|
||||
#include <QQmlContext>
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <QQmlApplicationEngine>
|
||||
#include <QmlNet/qml/JsNetObject.h>
|
||||
|
||||
QQmlApplicationEngine* sharedQmlEngine();
|
||||
|
||||
struct QQmlApplicationEngineContainer {
|
||||
QQmlApplicationEngine* qmlEngine;
|
||||
JsNetObject* netObject;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue