<?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] Call cpp method from qml in qt5.3]]></title><description><![CDATA[<p dir="auto">Hi, In qt 5.3, i have a cpp class (MainWindow) and i added a puch button on the ui. I want to click on the button, and open a window qml type "Window QML Type":<a href="http://qt-project.org/doc/qt-5/qml-qtquick-window-window.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/qml-qtquick-window-window.html</a><br />
I successfully can do that but i want to call a cpp function from qml window directly, how can i do that?<br />
I know that i can add a button in qml file and call cpp function by "onClicked:", i know it, but i want to call a cpp method directly after loading qml file, without clicking on any button. please help me.<br />
I want something like that:</p>
<p dir="auto">in qml file (mail.qml)<br />
window{<br />
id :qmlMainWindow<br />
color:white</p>
<pre><code>MainWindow {

    id : myCPPObject

}

//something like that
myCPPObject.cppFunction(&amp;#41;
</code></pre>
<p dir="auto">}</p>
<p dir="auto">//in mainwindow.h<br />
Q_INVOKABLE void cppFunction();</p>
<p dir="auto">//in main.cpp<br />
qmlRegisterType&lt;MainWindow&gt;("com.myself", 1, 0, "MainWindow");</p>
<p dir="auto">Thanks in advance...</p>
]]></description><link>https://forum.qt.io/topic/47219/solved-call-cpp-method-from-qml-in-qt5-3</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 09:30:49 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/47219.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 20 Oct 2014 08:06:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Call cpp method from qml in qt5.3 on Mon, 20 Oct 2014 08:57:40 GMT]]></title><description><![CDATA[<p dir="auto">Yes, that works.<br />
Thank you very much</p>
]]></description><link>https://forum.qt.io/post/248302</link><guid isPermaLink="true">https://forum.qt.io/post/248302</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 20 Oct 2014 08:57:40 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Call cpp method from qml in qt5.3 on Mon, 20 Oct 2014 08:43:36 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">If I understood you correctly you could call function in "Component.onCompleted":<a href="http://qt-project.org/doc/qt-5/qml-qtqml-component.html#completed-signal" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/qml-qtqml-component.html#completed-signal</a> handler.</p>
]]></description><link>https://forum.qt.io/post/248295</link><guid isPermaLink="true">https://forum.qt.io/post/248295</guid><dc:creator><![CDATA[p3c0]]></dc:creator><pubDate>Mon, 20 Oct 2014 08:43:36 GMT</pubDate></item></channel></rss>