<?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[Qt and scripting]]></title><description><![CDATA[<p dir="auto">I have a bunch of classes which inherit from QObject that have a bunch of Q_PROPERTY members which represent commands my application can receive.  I have a class which waits on a socket, gets some bytes, and then turns the bytes into one of my command classes.  This controller then emits a signal so that other parts of the program can respond to the commands that come in (the command is passed in the signal).</p>
<p dir="auto">Is there a way using one of the various scripting engines (QScript, QJSEngine) that I can easily script inserting different sets of commands?  I'd like to be able to say in the script:</p>
<p dir="auto">Make X Command<br />
X.param1 = 3<br />
X.param2 = 27</p>
<p dir="auto">Make Y Command<br />
Y.param1 = foo</p>
<p dir="auto">Send X<br />
Send Y</p>
<p dir="auto">Or something like that.</p>
<p dir="auto">Everything I've found to read about the script engines is related to QML and GUIs, which are not what I am doing here...</p>
]]></description><link>https://forum.qt.io/topic/32890/qt-and-scripting</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 12:18:33 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/32890.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Oct 2013 18:51:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Qt and scripting on Fri, 11 Oct 2013 06:30:47 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="JKSH" date="1381418341"]No, Qt Script is NOT part of Qt Core.[/quote]<br />
oops...you are right. My fault sorry.</p>
]]></description><link>https://forum.qt.io/post/198645</link><guid isPermaLink="true">https://forum.qt.io/post/198645</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 11 Oct 2013 06:30:47 GMT</pubDate></item><item><title><![CDATA[Reply to Qt and scripting on Thu, 10 Oct 2013 15:19:01 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="raven-worx" date="1381412701"]QtScript is part of Qt core. Also QML uses it...[/quote]No, Qt Script is NOT part of Qt Core.</p>
<p dir="auto">Qt Quick 1 (deprecated, also known as Qt Declarative) uses Qt Script. Qt Quick 2 does not.</p>
<p dir="auto"><a href="http://qt-project.org/doc/qt-5.1/qtdoc/addons.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtdoc/addons.html</a></p>
<p dir="auto"><em>"Qt Script: This module is primarily provided for compatibility with Qt 4, and to support applications that use the Qt Declarative Module. An alternative API is provided by the essential Qt Qml Module."</em></p>
<p dir="auto">[quote author="medvedm" date="1381408092"]Can you please explain how, via QML, I can tie objects in my C++ code w/ Q_PROPERTY members to JS?  I guess I don't get it.[/quote]How to convert C++ objects into QML objects:</p>
<ul>
<li><a href="http://qt-project.org/doc/qt-5.1/qtqml/referenceexamples-adding.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtqml/referenceexamples-adding.html</a></li>
<li><a href="http://qt-project.org/doc/qt-5.1/qtqml/referenceexamples-adding-main-cpp.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtqml/referenceexamples-adding-main-cpp.html</a></li>
</ul>
<p dir="auto">How to run JavaScript code in QML:</p>
<ul>
<li><a href="http://qt-project.org/doc/qt-5.1/qtdoc/qtquick-usecase-integratingjs.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtdoc/qtquick-usecase-integratingjs.html</a></li>
</ul>
<p dir="auto">How to create QML objects in JavaScript</p>
<ul>
<li><a href="http://qt-project.org/doc/qt-5.1/qtqml/qtqml-javascript-dynamicobjectcreation.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtqml/qtqml-javascript-dynamicobjectcreation.html</a></li>
</ul>
]]></description><link>https://forum.qt.io/post/198595</link><guid isPermaLink="true">https://forum.qt.io/post/198595</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Thu, 10 Oct 2013 15:19:01 GMT</pubDate></item><item><title><![CDATA[Reply to Qt and scripting on Thu, 10 Oct 2013 13:45:01 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="medvedm" date="1381411337"]Yeah, except you'll notice in this case you have to instantiate the class outside of the script and then pass it in.  I want the script to inst the class.<br />
[/quote]</p>
<p dir="auto">ok, then you will need to expose the class structure (QMetaObject) to QtScript.</p>
<p dir="auto">@<br />
QScriptValue myScriptClass = engine.scriptValueFromQMetaObject&lt;MyClass&gt;();<br />
engine.globalObject().setProperty("MyClass", myScriptClass);<br />
@</p>
<p dir="auto">Then you can use in your script:<br />
@<br />
var x = new MyClass;<br />
@</p>
<p dir="auto">But read this for "details":<a href="http://qt-project.org/doc/qt-5.0/qtscript/qtscript-index.html#making-a-qobject-based-class-new-able-from-a-script" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.0/qtscript/qtscript-index.html#making-a-qobject-based-class-new-able-from-a-script</a>.</p>
<p dir="auto">[quote author="medvedm" date="1381411337"]<br />
Also, I agree w/ the prev poster - QtScript sounds like it has lost favor to QJSEngine.<br />
[/quote]<br />
QtScript is part of Qt core. Also QML uses it...</p>
]]></description><link>https://forum.qt.io/post/198582</link><guid isPermaLink="true">https://forum.qt.io/post/198582</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Thu, 10 Oct 2013 13:45:01 GMT</pubDate></item><item><title><![CDATA[Reply to Qt and scripting on Thu, 10 Oct 2013 13:22:17 GMT]]></title><description><![CDATA[<p dir="auto">Yeah, except you'll notice in this case you have to instantiate the class outside of the script and then pass it in.  I want the script to inst the class.</p>
<p dir="auto">Also, I agree w/ the prev poster - QtScript sounds like it has lost favor to QJSEngine.</p>
]]></description><link>https://forum.qt.io/post/198577</link><guid isPermaLink="true">https://forum.qt.io/post/198577</guid><dc:creator><![CDATA[medvedm]]></dc:creator><pubDate>Thu, 10 Oct 2013 13:22:17 GMT</pubDate></item><item><title><![CDATA[Reply to Qt and scripting on Thu, 10 Oct 2013 13:18:58 GMT]]></title><description><![CDATA[<p dir="auto">use QtScript module. Taken from the "docs":<a href="http://qt-project.org/doc/qt-5.0/qtscript/qtscript-index.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.0/qtscript/qtscript-index.html</a> you could do this:<br />
@<br />
QScriptEngine engine;<br />
QObject *someObject = new MyObject;<br />
QScriptValue objectValue = engine.newQObject(someObject);  //expose your object to the script so you can access it from your scripts<br />
engine.globalObject().setProperty("myObject", objectValue);</p>
<p dir="auto">engine.evaluate(....);   //&lt;-- pass your script<br />
@</p>
]]></description><link>https://forum.qt.io/post/198576</link><guid isPermaLink="true">https://forum.qt.io/post/198576</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Thu, 10 Oct 2013 13:18:58 GMT</pubDate></item><item><title><![CDATA[Reply to Qt and scripting on Thu, 10 Oct 2013 12:28:12 GMT]]></title><description><![CDATA[<p dir="auto">Can you please explain how, via QML, I can tie objects in my C++ code w/ Q_PROPERTY members to JS?  I guess I don't get it.</p>
]]></description><link>https://forum.qt.io/post/198568</link><guid isPermaLink="true">https://forum.qt.io/post/198568</guid><dc:creator><![CDATA[medvedm]]></dc:creator><pubDate>Thu, 10 Oct 2013 12:28:12 GMT</pubDate></item><item><title><![CDATA[Reply to Qt and scripting on Wed, 09 Oct 2013 23:34:16 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">QML is simply a CSS- like language with full JavaScript support. It is mainly used to create GUIs, but it can certainly be used for other things too.</p>
<p dir="auto">QML makes an excellent bridge between QObjects and JavaScript -- it is tightly integrated with the Qt object model so it has full access to your Q_PROPERTY members. Through it, you can easily manipulate your QObjects using JavaScript.</p>
<p dir="auto">QJSEngine is a low-level component of the QML engine; writing QML code  gives you more power than using QJSEngine directly. Qt Script is now deprecated so I don't recommend using that.</p>
]]></description><link>https://forum.qt.io/post/198475</link><guid isPermaLink="true">https://forum.qt.io/post/198475</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Wed, 09 Oct 2013 23:34:16 GMT</pubDate></item></channel></rss>