How to invoke qml object from qt C



  • I can't find any link on interacting QML objects from C++
    I need to change the rectangle color in qml from red to green. Please assist.

    @
    ---------------------h file

    signals:
    void redcolor();
    void greencolor();

    ---------------------cpp file
    QStateMachine machine;
    QState *group= new QState();
    group->setObjectName("MyGroup");
    QTimer timer;
    timer.setInterval(1250);
    timer.setSingleShot(true);
    QObject::connect(group,SIGNAL(entered()),&timer, SLOT(start()));

    QState *state1;
    QState *state2;

    state1=function1(emit redcolor;);
    state2=function2(emit greencolor;);

    }

    -------------------------------------qml

    Item{
    id:container
    width:300; height:300

          Rectangle{
                      id:rect
                      width:190; height:190
                      color: "red"
                   MouseArea{
                          id:mouseArea
                          anchors.fill: parent
                        }
                    onColorChanged?rect.color= green: rect.color=red;
         }
    

    }

    @


  • Moderators


Log in to reply
 

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