Exchange data between "pure" C++ and QML

  • Hi

    I'm making a small test application which has a QML UI and some "pure" c++ logic (by which i mean it doesn't depend on the Qt framework). On my model side, I have a Workflow class which has a vector of Workflow Steps. Each Worfklow step has a name. The workflow also has a currently "active" Workflow Step My UI has a button which cycles through the workflow steps (basically, it instructs the workflow to make the next Workflow Step in it's vector the active Workflow Step).
    I've made a class, WorkflowQMLInterface (Q_OBJECT) which has a pointer to my pure c++ Workflow class and has some Q_INVOKABLE methods (asking the name of Workflow Step with index i, check if a Workflow Step with index i is the active workflow,... all using the Workflow member of this class to get the correct values). My QML UI uses this interface (.rootContext()->setContextProperty("workflowQML", WorkflowQMLInterface )) to query the model for the data. So far, so good. now my UI lists all the workflow steps with the active step being printed in bold. I also have a button in my UI which instructs the workflow to go to the next step (by invoking a method of WorkflowQMLInterface which updates the model). The model gets updated when I press this button, but my UI doesn't follow (the next workflow step doesn't become bold). What is the best way to make the UI follow the model (is it even possible)? Or do you have another way of working to keep your logic independent from the UI framework?


    Ps: I know that I could rewrite my model to use Q_PROPERTIES, but I want it to be as framework independent as possible.

  • Moderators

    You need Q_PROPERTY. In Qt 5.1 you can also use MEMBER parameter for Q_PROPERTY, which should make it easier to type.

    Or you need to force an update when your C++ stuff changes. This is very suboptimal, as it requires to basically delete the view and instantiate it again.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.