C++ QML TableView模型是否静默失败?
编辑:添加了一些澄清 使用QML 5.14 TableView的C++ QML TableView模型是否静默失败?,c++,qt,model,qml,tableview,C++,Qt,Model,Qml,Tableview,编辑:添加了一些澄清 使用QML 5.14 TableView的model属性似乎不希望显示QList,或int的任何变体,无论是qint8、qint32,等等。我可以让它与未签名的QList一起工作,但是我需要在应用程序中保留负值范围 我发现信息正在进入qml层,因为当我调用时: console.log("cfs.amounts is " + cfs.amounts) console.log("model is " + model) console.lo
model
属性似乎不希望显示QList
,或int
的任何变体,无论是qint8
、qint32
,等等。我可以让它与未签名的QList
一起工作,但是我需要在应用程序中保留负值范围
我发现信息正在进入qml层,因为当我调用时:
console.log("cfs.amounts is " + cfs.amounts)
console.log("model is " + model)
console.log("modellength is " + model.length)
我实际上得到了预期的控制台输出:
qml: cfs.amounts is 11,12
qml: model is 11,12
qml: modellength is 2
我通过直接传递数据,即模型:[11,22]
确保了TableView的功能,并正确显示,即显示索引0,1
。但是,当我在C++中通过<代码> CFS。因此,根据中继器项在其模型中识别它。我已经搜索过了,但找不到任何关于这个主题的bug报告。有人对如何让qml模型识别通过的QList
有什么建议吗?这都在QML 5.14中
cashflowschedule.h
#ifndef CASHFLOWSCHEDULE_H
#define CASHFLOWSCHEDULE_H
#include "QObject"
#include "QList"
class CashFlowSchedule : public QObject
{
Q_OBJECT
Q_PROPERTY(QList<int> amounts READ amounts)
public:
CashFlowSchedule() {};
QList<int> amounts() { return {11,12}; }
};
#endif // CASHFLOWSCHEDULE_H
包含在main.cpp中
#include "cashflowschedule.h"
...
qmlRegisterType<CashFlowSchedule>("cpps", 1, 0, "CashFlowSchedule");
...
#包括“cashflowschedule.h”
...
qmlRegisterType(“cpps”,1,0,“现金流量表”);
...
<代码> > p> <代码> qlist 不是用于模型的官方支持的C++类型之一(参见列表)。存在一个澄清这一点的文件。QVariantList是一个很好的替代品。现在,您使用的是text:index
,它只会显示索引。您是否尝试了text:modelData
?正确。我只想显示索引。目前,text:index
edit:完全不显示任何内容,text:modelData
的行为也类似。QVariantList也有其固有的缺陷。。。就像它根本不起作用。这能回答你的问题吗?
#include "cashflowschedule.h"
...
qmlRegisterType<CashFlowSchedule>("cpps", 1, 0, "CashFlowSchedule");
...