diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-01-28 14:34:43 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-01-28 15:11:08 +0000 |
commit | f36555f077d215dbef0ebd36b8f7a5877528d1cc (patch) | |
tree | 5a586a4d19929565cf038d8994c74f08f62ac256 /src/libs/installer/scriptengine.cpp | |
parent | d7ce2ba4a78e4c056f06bd89da43f50458462ad0 (diff) |
Make sure component wrapper is not deleted in advance
Use ScriptEngine::newQObject instead of the stock QScriptEngine one.
This one (among other things) sets object ownership to Cpp, preventing
dubious "cannot call name on undefined" script failures if the garbage
collector runs.
Change-Id: Ib3275012d307533c13de3520f4630d1eeee66869
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/scriptengine.cpp')
-rw-r--r-- | src/libs/installer/scriptengine.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp index 0d41e812d..6d776db88 100644 --- a/src/libs/installer/scriptengine.cpp +++ b/src/libs/installer/scriptengine.cpp @@ -294,6 +294,13 @@ namespace QInstaller { \qmlsignal gui::settingsButtonClicked(); */ +QJSValue InstallerProxy::componentByName(const QString &componentName) +{ + if (m_core) + return m_engine->newQObject(m_core->componentByName(componentName)); + return QJSValue(); +} + GuiProxy::GuiProxy(ScriptEngine *engine, QObject *parent) : QObject(parent), m_engine(engine), @@ -503,7 +510,7 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) : QJSValue global = m_engine.globalObject(); global.setProperty(QLatin1String("console"), m_engine.newQObject(new ConsoleProxy)); global.setProperty(QLatin1String("QFileDialog"), m_engine.newQObject(new QFileDialogProxy)); - const QJSValue proxy = m_engine.newQObject(new InstallerProxy(&m_engine, core)); + const QJSValue proxy = m_engine.newQObject(new InstallerProxy(this, core)); global.setProperty(QLatin1String("InstallerProxy"), proxy); global.setProperty(QLatin1String("print"), m_engine.newQObject(new ConsoleProxy) .property(QLatin1String("log"))); @@ -558,6 +565,9 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) : QJSValue ScriptEngine::newQObject(QObject *object) { QJSValue jsValue = m_engine.newQObject(object); + if (!jsValue.isQObject()) + return jsValue; + QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); // add findChild(), findChildren() methods known from QtScript |