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 filesignals:
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:300Rectangle{ id:rect width:190; height:190 color: "red" MouseArea{ id:mouseArea anchors.fill: parent } onColorChanged?rect.color= green: rect.color=red; }
}
@
-
Hi,
Have a look at "this":http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html document.