<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Hello, </p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">I want to invoke a function from QML Python. I use this: </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">obj</span><span style=" font-weight:600; font-style:italic; color:#000000;">=</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">app</span><span style=" font-weight:600; font-style:italic; color:#000000;">.</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">rootObjects</span><span style=" font-weight:600; font-style:italic; color:#000000;">()</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">myObject</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">=</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">obj</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">[</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000080;">0</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">].</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">findChild</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">(</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">QObject</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">,</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#008000;">'myObj'</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">QMetaObject</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">.</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">invokeMethod</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">(</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">myObject</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">,</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#008000;">"myTest"</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">,</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">Qt</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">.</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">DirectConnection)</span></p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">It works fine, but now I have to pass arguments. </p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">I tried this: </p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">obj</span><span style=" font-weight:600; font-style:italic; color:#000000;">=</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">app</span><span style=" font-weight:600; font-style:italic; color:#000000;">.</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">rootObjects</span><span style=" font-weight:600; font-style:italic; color:#000000;">()</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">myObject</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">=</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">obj</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">[</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000080;">0</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">].</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">findChild</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">(</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">QObject</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">,</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#008000;">'myObject'</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">QMetaObject</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">.</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">invokeMethod</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">(</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">myObject</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">,</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#008000;">"myTest"</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">,</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">Qt</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#000000;">.</span><span style=" font-family:'Monospace'; font-weight:600; font-style:italic; color:#000000; background-color:#ffffff;">DirectConnection, Q_ARG(int, 1020</span></p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Monospace'; color:#000000; background-color:#ffffff;">My QML function :</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-weight:600; font-style:italic; color:#808000;">function</span><span style=" font-weight:600; font-style:italic; color:#000000;">myTest</span><span style=" font-weight:600; font-style:italic;">(x){</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#0055af;"> console</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic;">.log(</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic; color:#2985c7;">x</span><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic;">)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-family:'Courier New,courier'; font-weight:600; font-style:italic;">}</span></p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">But I have this error in return: </p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-weight:600; font-style:italic;">QMetaObject::invokeMethod: No such method MyQML_QMLTYPE_100::myTest(int)</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-weight:600; font-style:italic;">QMetaObject.invokeMethod(myObject, "myTest", Qt.DirectConnection, Q_ARG(int, 1020))</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><span style=" font-weight:600; font-style:italic;">RuntimeError: QMetaObject.invokeMethod() call failed</span></p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Can you help me? </p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">In advance thank you</p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Charlie</p></body></html>