Home > Article > Backend Development > How to Connect C Signals to QML Slots with QString Parameters?
Connecting C Signals to QML Slots
Issue:
When attempting to send a QString parameter from a C signal to a QML slot, an error occurs stating, "No such slot QDeclarativeRectangle_QML_2::updateViewWithItem(QString)."
Solution:
Using Connections
To resolve this issue, connections should be employed instead of direct slot connections.
Expose C Object to QML:
Add the C object (myObj) to the QML context property using setContextProperty() in the main C code.
<code class="cpp">qmlVectorForm->rootContext()->setContextProperty("YourObject", myOb);</code>
Define Signal:
In C , define the signal as:
<code class="cpp">finishedGatheringDataForItem(QString signalString);</code>
Add Connections in QML:
In the QML file, add connections to the exposed object:
<code class="qml">Connections { target: YourObject onFinishedGatheringDataForItem: { qmlString = signalString } }</code>
By using connections, the QML slot can receive the QString parameter correctly without the previous error.
The above is the detailed content of How to Connect C Signals to QML Slots with QString Parameters?. For more information, please follow other related articles on the PHP Chinese website!