A.qml
function getInvoice() {
return invoice;
}
function setInvoice(invoice1) {
invoice = invoice1;
console.log("-------invoice is "+ invoice);//invoice输出的是一组json数据,这里是从c++获取到的
}
这里invoice输出的内容是{"purchaser":{"name":"555555555551","code":"123"},
"totalAmount":123,
"totalAmountOfTax":0,
"totalAmountAndTax":0,
"invoiceItem":[[0,"电脑",0,123,1,null,0,123,0,0],null,null,null,null,null,null,null,null,null]
}
我想在B.qml中显示A中的invoice中的某个字段
请问有大神听懂我在说什么吗,小白求教
------解决思路----------------------
// B.qml
QtObject
{
A { id: a }
Component.onCompleted:
{
console.log( a.getInvoice( ).purchaser.code );
}
}
运行”qmlscene B.qml ”试试看。
------解决思路----------------------
你传入的是字符串,这么用:
var jsonObj = JSON.parse(jsonString);
console.log(jsonObj.totalAmount);
我的书《Qt Quick核心编程》里都有讲到。