Solved Problem with c++ to qml emiting
-
Hi! I have some code. But I have problems with It. Cause I can't append to ListView something. When app start and starting changer() I have call of function, which emit signal to qml, but in qml nothing happens.
In list view I have some pic+text+tooltip.
main.cpp qmlRegisterType<changer>("Changer",1,0,"Changer"); changer.cpp bool changer::add(std::string uid, QString name, QString place, QString type){ place_uid.push_back(uid); emit adding(name,"0","good",place); qDebug() <<"pew-pew"; return 1; } signals: void adding(QString idfromapp,QString data, QString sig, QString place); main.qml import Changer 1.0 Changer{ id: changeit } Connections { target: changeit onUpdate: { update(idbutt,idfromapp,data,sig,place)} onUpdateMeasure: { updateMeasure(idbutt,data,sig) } onRemove: { remove(idbutt) } onAdding: { add_component(idfromapp,data,sig,place) } } function add_component(idfromapp,data,sig,place){ listMod.append({"attributes": [{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]}) }
Can somebody e3xplain what I doing wrong?
-
At least I solved It. The problem was in ListView. I need just write anchors.fill : parent, and now all work!
-
@Adamas Why do you use Connections ?
It's more readable to declare signals connection direct on instance:
import Changer 1.0 Changer{ id: changeit onUpdate: { update(idbutt,idfromapp,data,sig,place) } onUpdateMeasure: { updateMeasure(idbutt,data,sig) } onRemove: { remove(idbutt) } onAdding: { add_component(idfromapp,data,sig,place) } } function add_component(idfromapp,data,sig,place){ listMod.append({"attributes": [{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]}) }
-
At least I solved It. The problem was in ListView. I need just write anchors.fill : parent, and now all work!
-
listMod.append({"attributes": [{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]})
You know, In my struct it doesn't work. In this case it write only default attributes