<?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[[Solved] Sending C++ values to QML properties]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I trying to change some QML properties from C++ in order to rotate one object but looks like it doesn't update or repaint. I followed this document:</p>
<p dir="auto"><a href="http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html</a></p>
<p dir="auto">...but once i change the property i debug it, the value is correct but the object didn't rotate. This is how i change the property and how i read it with the debug:</p>
<p dir="auto">object-&gt;setProperty("canvas3d.xRotSlider", 90);<br />
qDebug() &lt;&lt; "Property value:" &lt;&lt; object-&gt;property("canvas3d.xRotSlider").toDouble();</p>
<p dir="auto">Any suggestion?<br />
Thanks!</p>
]]></description><link>https://forum.qt.io/topic/56526/solved-sending-c-values-to-qml-properties</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Nov 2026 18:48:25 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/56526.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 20 Jul 2015 12:03:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved] Sending C++ values to QML properties on Wed, 22 Jul 2015 08:28:11 GMT]]></title><description><![CDATA[<p dir="auto">In my case is opposite. I have a C++ project and now I want to display a 3D model rotating depending on the moving of some sensors. So as i never used QML before i integrated in my old form a Widget container with a QQuickView inside to show the model. I took some json models from the examples to make it working, and actually i have my own designed model in 3Dstudio and Solidworks to replace the sample, but i'm "googling" in order to make that step between, seems not trivial...</p>
]]></description><link>https://forum.qt.io/post/283271</link><guid isPermaLink="true">https://forum.qt.io/post/283271</guid><dc:creator><![CDATA[avmg]]></dc:creator><pubDate>Wed, 22 Jul 2015 08:28:11 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Sending C++ values to QML properties on Mon, 20 Jul 2015 22:48:57 GMT]]></title><description><![CDATA[<p dir="auto">Glad to be of assistance :)</p>
<p dir="auto">I don't know what your project is like. For the most part, I use QML for UI and one (or more) similar integration classes for all the C++ code. Therefore, my main loop is in QML and it calls C++ through the integration class(es), just like I would in the widget-based Qt app call methods when a specific menu item was clicked or something similar. Thus my whole C++ part of the application is instantiated from QML, and it can have signals, slots, trees of new classes and everything else bellow the "main" C++ entry point object.</p>
]]></description><link>https://forum.qt.io/post/283098</link><guid isPermaLink="true">https://forum.qt.io/post/283098</guid><dc:creator><![CDATA[brcha]]></dc:creator><pubDate>Mon, 20 Jul 2015 22:48:57 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Sending C++ values to QML properties on Mon, 20 Jul 2015 19:39:59 GMT]]></title><description><![CDATA[<p dir="auto">Finally i could. I create a function in the QML file to be called from the C++ application. This is mostly the same i tryied at the begining but instead modifying the property from a inherited C++ class i was trying to  change the property from an instance created with JavaScript as the "barrel" example that comes with Qt5.5 (in this case the property is change with a slider). The difference is that now when i change the property the event is triggering and before not, i don't know the reason...</p>
<p dir="auto">Thanks brcha for the help!</p>
]]></description><link>https://forum.qt.io/post/283057</link><guid isPermaLink="true">https://forum.qt.io/post/283057</guid><dc:creator><![CDATA[avmg]]></dc:creator><pubDate>Mon, 20 Jul 2015 19:39:59 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Sending C++ values to QML properties on Mon, 20 Jul 2015 17:36:04 GMT]]></title><description><![CDATA[<p dir="auto">Cool!</p>
<p dir="auto">I did what you explained and now i have a C++ class with some Q_PROPERTY's and some functions to modify them from C++. I did some tests to verify the connection between the QML and the new class. But now, as the instance of this class is on QML, How can i access it from C++ in order to change the properties?</p>
]]></description><link>https://forum.qt.io/post/283041</link><guid isPermaLink="true">https://forum.qt.io/post/283041</guid><dc:creator><![CDATA[avmg]]></dc:creator><pubDate>Mon, 20 Jul 2015 17:36:04 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Sending C++ values to QML properties on Mon, 20 Jul 2015 16:36:46 GMT]]></title><description><![CDATA[<p dir="auto">The best way to interact between C++ and QML is to make a class that inherits QQuickItem and create Q_PROPERTY-es in it, then register it in your main (or somewhere else) and import it into QML. For example:</p>
<pre><code>class TestIntegration : public QQuickItem 
{
    Q_OBJECT
    
    Q_PROPERTY(int testProperty READ testProperty WRITE setTestProperty NOTIFY testPropertyChanged)
public:
    TestIntegration(QQuickItem*parent=0)
      : QQuickItem(parent)
      , m_testProperty(0)
    {}

    int testProperty() const { return m_testProperty; }

public slots:
    void setTestProperty(int testProperty)
    {
        m_testProperty = testProperty;
        emit testPropertyChanged;
    }

signals:
    void testPropertyChanged(int testProperty);

protected:
    int m_testProperty;
}
</code></pre>
<p dir="auto">Note that the above code can be autogenerated by QtCreator. You just start Q_PROP and it autocompletes it to the entire Q_PROPERTY asking you to set the type and the name of the property. Then you can rightclick Q_PROPERTY and in refactor submenu generate all methods and the field.</p>
<p dir="auto">After that you just register the class in your main</p>
<pre><code>int main(int argc, char**argv)
{
    ...
    qmlRegisterType&lt;TestIntegration&gt;("YourNamespace", 1, 0, "TestIntegration");
    ...
}
</code></pre>
<p dir="auto">and in QML you import it and make the object somewhere</p>
<pre><code>import YourNamespace 1.0;

TestIntegration {
    id: testIntegration
}
</code></pre>
<p dir="auto">and use the property how ever you like</p>
<pre><code>randomQmlProperty = testIntegration.testProperty
</code></pre>
<p dir="auto">or</p>
<pre><code>testIntegration.testProperty = whateverYouSetFromQml
</code></pre>
]]></description><link>https://forum.qt.io/post/283036</link><guid isPermaLink="true">https://forum.qt.io/post/283036</guid><dc:creator><![CDATA[brcha]]></dc:creator><pubDate>Mon, 20 Jul 2015 16:36:46 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Sending C++ values to QML properties on Mon, 20 Jul 2015 14:58:47 GMT]]></title><description><![CDATA[<p dir="auto">My starting project was the barrel example, it includes js with qml, but instead to rotate the barrel with the sliders i would like to rotate with a given C++ variables values. But i had no success sending the values to the QML neither changing the angles on the js script... I expected something easy and common but is being impossible.</p>
]]></description><link>https://forum.qt.io/post/283022</link><guid isPermaLink="true">https://forum.qt.io/post/283022</guid><dc:creator><![CDATA[avmg]]></dc:creator><pubDate>Mon, 20 Jul 2015 14:58:47 GMT</pubDate></item></channel></rss>