how can i change the text of the button without clicked in the listview delegate?
当我解决了上面的问题时,有一个新的问题。我不能使用工作程序来同步模型,但是当我在工作中使用sync时,尽管它在qtcreator中有一些错误,但是它可以同步模型中的数据角色,通常,同步将失败。
dataloader.js:
WorkerScript.onMessage = function(msg) {
msg.model.sync();
}
PrinterList.qml:
WorkerScript{
id:worker
source:"dataloader.js"
}
function cmpPname(prnName)
{
console.log("cmpPname");
var tmpName = prnName.replace(/_/g," ");
console.log("tmpName=",tmpName);
var pname = new Array;
pname= Jsclient.g_str.split(',');
tmpName = tmpName.split(',');
console.log("pModel.count=",pModel.count);
for(var i = 0;i < pname.length;i++){
if(tmpName == pname[i]){
console.log("pname[%1]=".arg(i),pname[i]);
Jsclient.pstate = "Added";
pModel.setProperty(i,"prstate",qsTr(Jsclient.pstate));
// pModel.get(2).prstate = qsTr(Jsclient.pstate);
sync(); **//this works!!but often failed too.**
}else{
Jsclient.pstate = "Add";
pModel.setProperty(i,"prstate",qsTr(Jsclient.pstate));
}
worker.sendMessage({"model":pModel}); **//this failed,why?**
}
}
答案 0 :(得分:0)
最后,我解决了这个问题。 dataloader.js:
WorkerScript.onMessage = function(msg) {
console.log(msg.index,msg.prstate);
msg.model.setProperty(msg.index,"prstate",msg.prstate);
msg.model.sync();
}
list.qml:
worker.sendMessage({"index":i,"prstate":qsTr("Added"),"model":pModel});