Call function in ui.qml!
-
thank you for your response
I started a project on Qt Design Studio and then convert it into a Quick project
Now the only files I have are ui.qml files
Now I need to call the signals from the c ++ files
this is my question: how can i call c++ function when i clicked on a shape in ui.qml file? -
To call CPP function in Screen1.ui.qml ... im renaming file name to Screen1.qml ... is it proper way to call functions?
@ODБOï could you provide guidance how can we call functions in the component(.qml)... e.g. i need to call function when button clicked.
-
You need to create a model with
Q_INVOKABLEfunction:class MyModel : public QObject { Q_OBJECT QML_ELEMENT MyModel() = default; ~MyModel() = default; public: Q_INVOKABLE void doSomething(); };Then add it to your QML Widget:
import Your.App.Namespace Item { MyModel { id: myModel } }Then you can use
myModel.doSomething().Maybe read the QML documentation or contribute to a QML project to see how it works? I learnt all this while forking MuseScore.