* [PATCH] phonesim: fix exporting of child widgets to javascript engine
@ 2025-12-29 8:10 Andres Salomon
2026-02-27 21:27 ` Andres Salomon
2026-11-14 6:13 ` Herman van Hazendonk
0 siblings, 2 replies; 3+ messages in thread
From: Andres Salomon @ 2025-12-29 8:10 UTC (permalink / raw)
To: ofono
Using the example sms.js script in doc/scriptable.txt, the following
error occurs with phonesim built using Qt5.15:
Error org.ofono.phonesim.Error.ScriptExecError: /tmp/sms.js, line 1, TypeError: Cannot read property 'leMessageSender' of undefined
This is due to phonesim creating javascript objects for all the gui
tab widgets, but none of the child widgets inside of those tabs. So
in the javascript engine, 'tabSMS' is available, but its child widget
'gbMessage1' is undefined.
I'm not sure if this is related to behavior changes in current versions
of QJSEngine/UIC or what, but we can manually add all those widgets
to the javascript engine to fix this.
---
src/control.cpp | 25 +++++++++++++++++++++++++
src/control.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/src/control.cpp b/src/control.cpp
index 817a0b2..b85e9ad 100644
--- a/src/control.cpp
+++ b/src/control.cpp
@@ -637,32 +637,57 @@ void ControlWidget::modemSilentReset()
emit unsolicitedCommand("+CRST:");
}
+/*
+ * Recursively add all widgets in a controlbase.ui tab to the javascript
+ * engine so that scripts can reference them. Because the widgets
+ * aren't local to this function, they should remain in scope while the
+ * script executes.
+ */
+void Script::AddChildren(const QWidget *parentW, QJSValue &parentJS)
+{
+ QList<QWidget*> kids = parentW->findChildren<QWidget*>(QString(),
+ Qt::FindDirectChildrenOnly);
+ foreach (QWidget *w, kids) {
+ QJSValue obj = engine.newQObject(w);
+ parentJS.setProperty(w->objectName(), obj);
+ AddChildren(w, obj);
+ }
+}
+
Script::Script(QObject *obj, Ui_ControlBase *ui) : QDBusAbstractAdaptor(obj)
{
/* Export tabs to be accessed by script */
QJSValue qsTab = engine.newQObject(ui->tab);
engine.globalObject().setProperty("tabRegistration", qsTab);
+ AddChildren(ui->tab, qsTab);
QJSValue qsTab2 = engine.newQObject(ui->tab_2);
engine.globalObject().setProperty("tabCBM", qsTab2);
+ AddChildren(ui->tab_2, qsTab2);
QJSValue qsTab3 = engine.newQObject(ui->tab_3);
engine.globalObject().setProperty("tabSMS", qsTab3);
+ AddChildren(ui->tab_3, qsTab3);
QJSValue qsTab4 = engine.newQObject(ui->tab_4);
engine.globalObject().setProperty("tabVoiceMail", qsTab4);
+ AddChildren(ui->tab_4, qsTab4);
QJSValue qsTab5 = engine.newQObject(ui->tab_5);
engine.globalObject().setProperty("tabUSSD", qsTab5);
+ AddChildren(ui->tab_5, qsTab5);
QJSValue qsTab6 = engine.newQObject(ui->tab_6);
engine.globalObject().setProperty("tabSIM", qsTab6);
+ AddChildren(ui->tab_6, qsTab6);
QJSValue qsTab8 = engine.newQObject(ui->tab_8);
engine.globalObject().setProperty("tabPosition", qsTab8);
+ AddChildren(ui->tab_8, qsTab8);
QJSValue qsTab9 = engine.newQObject(ui->tab_9);
engine.globalObject().setProperty("tabCall", qsTab9);
+ AddChildren(ui->tab_9, qsTab9);
}
void Script::SetPath(const QString &path, const QDBusMessage &msg)
diff --git a/src/control.h b/src/control.h
index be4a366..c160d61 100644
--- a/src/control.h
+++ b/src/control.h
@@ -57,6 +57,8 @@ public slots:
QString Run(const QString &name, const QDBusMessage &msg);
private:
+ void AddChildren(const QWidget *parentW, QJSValue &parentJS);
+
QString dirPath;
QJSEngine engine;
};
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] phonesim: fix exporting of child widgets to javascript engine
2025-12-29 8:10 [PATCH] phonesim: fix exporting of child widgets to javascript engine Andres Salomon
@ 2026-02-27 21:27 ` Andres Salomon
2026-11-14 6:13 ` Herman van Hazendonk
1 sibling, 0 replies; 3+ messages in thread
From: Andres Salomon @ 2026-02-27 21:27 UTC (permalink / raw)
To: ofono; +Cc: Marcel Holtmann
BTW Marcel, I noticed in the latest phonesim release (2.1) that the
tarball dropped the doc/scriptable.txt file. Was this unintentional, or
is the javascript interface being deprecated?
If it's not being deprecated, I'd love some feedback on this patch. :)
On 12/29/25 03:10, Andres Salomon wrote:
> Using the example sms.js script in doc/scriptable.txt, the following
> error occurs with phonesim built using Qt5.15:
>
> Error org.ofono.phonesim.Error.ScriptExecError: /tmp/sms.js, line 1, TypeError: Cannot read property 'leMessageSender' of undefined
>
> This is due to phonesim creating javascript objects for all the gui
> tab widgets, but none of the child widgets inside of those tabs. So
> in the javascript engine, 'tabSMS' is available, but its child widget
> 'gbMessage1' is undefined.
>
> I'm not sure if this is related to behavior changes in current versions
> of QJSEngine/UIC or what, but we can manually add all those widgets
> to the javascript engine to fix this.
> ---
> src/control.cpp | 25 +++++++++++++++++++++++++
> src/control.h | 2 ++
> 2 files changed, 27 insertions(+)
>
> diff --git a/src/control.cpp b/src/control.cpp
> index 817a0b2..b85e9ad 100644
> --- a/src/control.cpp
> +++ b/src/control.cpp
> @@ -637,32 +637,57 @@ void ControlWidget::modemSilentReset()
> emit unsolicitedCommand("+CRST:");
> }
>
> +/*
> + * Recursively add all widgets in a controlbase.ui tab to the javascript
> + * engine so that scripts can reference them. Because the widgets
> + * aren't local to this function, they should remain in scope while the
> + * script executes.
> + */
> +void Script::AddChildren(const QWidget *parentW, QJSValue &parentJS)
> +{
> + QList<QWidget*> kids = parentW->findChildren<QWidget*>(QString(),
> + Qt::FindDirectChildrenOnly);
> + foreach (QWidget *w, kids) {
> + QJSValue obj = engine.newQObject(w);
> + parentJS.setProperty(w->objectName(), obj);
> + AddChildren(w, obj);
> + }
> +}
> +
> Script::Script(QObject *obj, Ui_ControlBase *ui) : QDBusAbstractAdaptor(obj)
> {
> /* Export tabs to be accessed by script */
> QJSValue qsTab = engine.newQObject(ui->tab);
> engine.globalObject().setProperty("tabRegistration", qsTab);
> + AddChildren(ui->tab, qsTab);
>
> QJSValue qsTab2 = engine.newQObject(ui->tab_2);
> engine.globalObject().setProperty("tabCBM", qsTab2);
> + AddChildren(ui->tab_2, qsTab2);
>
> QJSValue qsTab3 = engine.newQObject(ui->tab_3);
> engine.globalObject().setProperty("tabSMS", qsTab3);
> + AddChildren(ui->tab_3, qsTab3);
>
> QJSValue qsTab4 = engine.newQObject(ui->tab_4);
> engine.globalObject().setProperty("tabVoiceMail", qsTab4);
> + AddChildren(ui->tab_4, qsTab4);
>
> QJSValue qsTab5 = engine.newQObject(ui->tab_5);
> engine.globalObject().setProperty("tabUSSD", qsTab5);
> + AddChildren(ui->tab_5, qsTab5);
>
> QJSValue qsTab6 = engine.newQObject(ui->tab_6);
> engine.globalObject().setProperty("tabSIM", qsTab6);
> + AddChildren(ui->tab_6, qsTab6);
>
> QJSValue qsTab8 = engine.newQObject(ui->tab_8);
> engine.globalObject().setProperty("tabPosition", qsTab8);
> + AddChildren(ui->tab_8, qsTab8);
>
> QJSValue qsTab9 = engine.newQObject(ui->tab_9);
> engine.globalObject().setProperty("tabCall", qsTab9);
> + AddChildren(ui->tab_9, qsTab9);
> }
>
> void Script::SetPath(const QString &path, const QDBusMessage &msg)
> diff --git a/src/control.h b/src/control.h
> index be4a366..c160d61 100644
> --- a/src/control.h
> +++ b/src/control.h
> @@ -57,6 +57,8 @@ public slots:
> QString Run(const QString &name, const QDBusMessage &msg);
>
> private:
> + void AddChildren(const QWidget *parentW, QJSValue &parentJS);
> +
> QString dirPath;
> QJSEngine engine;
> };
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] phonesim: fix exporting of child widgets to javascript engine
2025-12-29 8:10 [PATCH] phonesim: fix exporting of child widgets to javascript engine Andres Salomon
2026-02-27 21:27 ` Andres Salomon
@ 2026-11-14 6:13 ` Herman van Hazendonk
1 sibling, 0 replies; 3+ messages in thread
From: Herman van Hazendonk @ 2026-11-14 6:13 UTC (permalink / raw)
To: Andres Salomon; +Cc: ofono, Marcel Holtmann, Denis Kenzior
Hi Andres,
On Mon, 29 Dec 2025 03:10:53 -0500, Andres Salomon wrote:
> Using the example sms.js script in doc/scriptable.txt, the following
> error occurs with phonesim built using Qt5.15:
>
> Error org.ofono.phonesim.Error.ScriptExecError: /tmp/sms.js, line 1, TypeError: Cannot read property 'leMessageSender' of undefined
We hit the same thing in LuneOS and carry a fix of our own, so I gave
yours a run. On current master with Qt 5.15, the call.js and sms.js
examples from doc/scriptable.txt fail exactly as you describe. With
your patch both work: call.js produces +CRING/+CLIP for 12345 on the
AT side, sms.js a +CMTI, and a script reading
tabCall.gbIncomingCall.leCaller.text gets the number back.
> I'm not sure if this is related to behavior changes in current versions
> of QJSEngine/UIC or what
It goes back to 04e66fd ("Replace QtScript with QtQml"). QtScript made
every named child of an exported QObject a property of it; QJSEngine
only exposes properties, slots and invokables, so the scripts lost
their path to the widgets with that commit.
> + QList<QWidget*> kids = parentW->findChildren<QWidget*>(QString(),
> + Qt::FindDirectChildrenOnly);
> + foreach (QWidget *w, kids) {
One request: could this be a range-based for? phonesim was ported
away from Q_FOREACH in a2bb630, and builds that define QT_NO_FOREACH
(our CMake/Qt 6 build does) fail here with "expected primary-expression
before '*' token". Something like
const QList<QWidget *> kids = parentW->findChildren<QWidget *>(
QString(), Qt::FindDirectChildrenOnly);
for (QWidget *w : kids) {
builds cleanly with Qt 6 for armv7, aarch64 and x86-64 here.
Two smaller things you may or may not want to pick up; ours does both:
- widgets without an objectName (and Qt's own qt_* children, such as
the viewport of a QTextEdit) still get exported, as a property with
an empty or internal name;
- a child whose name matches a real property of its parent would
replace that property. Nothing in controlbase.ui collides today,
so this is only defensive.
Thanks for chasing this.
Herman
(The testing and this review were done with the help of Claude, an AI
assistant.)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-14 6:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-29 8:10 [PATCH] phonesim: fix exporting of child widgets to javascript engine Andres Salomon
2026-02-27 21:27 ` Andres Salomon
2026-11-14 6:13 ` Herman van Hazendonk
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.