Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Communication between C++ and QML
I want to change the image on a Button via a C++ function (trigger a state-change or however it is done).
How can I achieve this?
DenisKormalev last edited by
For example you can emit signal from cpp, cennect to it in qml via Connection and do there whatever you want. Or you can change property of your object (but to do it you need to find it in objects tree).
Ah thank you. Can I find an example on this here?
andre last edited by
One way is this:
You create a QObject derived class, that you give a property for the image URL, and make sure that property has a proper notify signal. Then, you put an instance of that class as a property in your QDeclarativeContext using setContextProperty. That makes the object accessible from within QML, where you can simply bind against the property name for the image URL.
ZapB last edited by
Take a look at this "thread":http://developer.qt.nokia.com/forums/viewthread/4491/#30571 and get a checkout of the code from subversion that I made. This demonstrates exactly what you need.
Thanks everyone. I figured it out due to your help.