<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QScriptEngine and QMetaObject]]></title><description><![CDATA[<p dir="auto">I am working based on the documentation of QScriptEngine with QMetaObject.<br />
I made my own class, inherited from QObject. It seems to work, but I have some problems.</p>
<p dir="auto">@ QScriptValue mySpecialQObjectConstructor(QScriptContext *context,<br />
QScriptEngine *engine)<br />
{<br />
QObject *parent = context-&gt;argument(0).toQObject();<br />
QObject *object = new QObject(parent);<br />
return engine-&gt;newQObject(object, QScriptEngine::ScriptOwnership);<br />
}</p>
<p dir="auto">...</p>
<p dir="auto">QScriptValue ctor = engine.newFunction(mySpecialQObjectConstructor);<br />
QScriptValue metaObject = engine.newQMetaObject(&amp;QObject::staticMetaObject, ctor);<br />
engine.globalObject().setProperty("QObject", metaObject);</p>
<p dir="auto">QScriptValue result = engine.evaluate("new QObject()");@</p>
<p dir="auto">Firstly, I can call the slots, but not the normal functions, from the script side. Why is that?<br />
If I give return value to my slots it seems to work, Is it a good practice?</p>
<p dir="auto"><a href="http://www.qtcentre.org/threads/59771-How-to-really-really-use-custom-QtScript-classes" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.qtcentre.org/threads/59771-How-to-really-really-use-custom-QtScript-classes</a></p>
<p dir="auto">Looking at the last post, he uses signals and slots:</p>
<p dir="auto">@x.mySignal.connect(y.mySlot);@</p>
<p dir="auto">What can be at the place of y.mySlot? Surely I can use an another registered QMetaObject. But can I use registered standalone functions? Or script side functions?</p>
<p dir="auto">Thanks in advance.</p>
]]></description><link>https://forum.qt.io/topic/47941/qscriptengine-and-qmetaobject</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 16:22:15 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/47941.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Nov 2014 22:25:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QScriptEngine and QMetaObject on Sat, 08 Nov 2014 23:31:21 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">No it's not, don't give a return value to a slot.</p>
<p dir="auto">However, you can use Q_INVOKABLE for your purpose.</p>
]]></description><link>https://forum.qt.io/post/250735</link><guid isPermaLink="true">https://forum.qt.io/post/250735</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 08 Nov 2014 23:31:21 GMT</pubDate></item></channel></rss>