Reputation: 61
I want to block a button in a qml file when my function in cpp is called.
How can I do this?
Upvotes: 1
Views: 186
Reputation: 19
In your c++ function you can emit signal of class, which should be visible in QML too:
void yourFunction() {
emit yourClassInstance.nameOfSignal;
}
You can register your class in QML:
engine->rootContext()->setContextProperty(<Name of your class in qml>, <reference to instance of your class>);
After that you can use Connection to connect signal from your c++ class to js function like that:
Connection {
target: <Name of your class in qml>
onNameOfSignal: {
// Disable button here
}
}
Upvotes: 0
Reputation: 48268
you have a button and lets say you are using qml and c++ you can interact between them as in de doc explained
then you can invoke the `setProperty` method
// Using QQmlComponent
QQmlEngine engine;
QQmlComponent component(&engine,
QUrl::fromLocalFile("MyItem.qml"));
QObject *object = component.create();
object->setProperty("width", 500);
...
delete object;
Upvotes: 1