<?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[Connect QML signal from delegate to C++ object]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I have a QML ListView with a button into the delegate Item. I'd like to know if it's possible connect a delegate Item signal to a particular C++ object slot.</p>
]]></description><link>https://forum.qt.io/topic/93979/connect-qml-signal-from-delegate-to-c-object</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 02:55:26 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/93979.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Aug 2018 20:50:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Connect QML signal from delegate to C++ object on Thu, 23 Aug 2018 21:29:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/fede">@<bdi>fede</bdi></a> hi,<br />
of course you can do that.<br />
Create your c++ class (subclass QObject)  and the slot you need</p>
<pre><code>class MyClass: public QObject  
{ 
    Q_OBJECT 
public: 
    explicit MyClass(QObject *parent = 0); 
  
signals: 
  
public slots: 
    void theSlot(){ ... }
}; 
  
</code></pre>
<p dir="auto">Create an instance of the class in main.cpp and use setContextProperty() methode to make your object reachable in QML<br />
<a href="http://doc.qt.io/qt-5/qqmlcontext.html#setContextProperty" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qqmlcontext.html#setContextProperty</a></p>
<pre><code>#include "myclass.h"
  
int main(int argc, char *argv[]) 
{ 
    QGuiApplication app(argc, argv); 
    MyClass c;  
    QQmlApplicationEngine engine; 
    engine.rootContext()-&gt;setContextProperty("myObj", &amp;c);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 
  
    return app.exec(); 
}
</code></pre>
<p dir="auto">then you can call <strong>theSlot()</strong></p>
<pre><code>..{
onClicked: myObj.theSlot()
}
</code></pre>
]]></description><link>https://forum.qt.io/post/477876</link><guid isPermaLink="true">https://forum.qt.io/post/477876</guid><dc:creator><![CDATA[ODБOï]]></dc:creator><pubDate>Thu, 23 Aug 2018 21:29:54 GMT</pubDate></item></channel></rss>