henrique vital
henrique vital

Reputation: 61

How to block a button in qml in a cpp file?

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

Answers (2)

Kostia Hvorov
Kostia Hvorov

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

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

Related Questions