[英]How to use removeRows with QStringListModel
I have a QStringListModel which works ok, but then I need to delete all the rows from it from QML . 我有一个可以正常工作的QStringListModel,但是我需要从QML删除它的所有行。
I would expect removeRowsfunction from Qt documentation work like that, but I don't know how to use it property. 我希望Qt文档中的removeRowsfunction可以那样工作,但是我不知道如何使用它的属性。
removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
I tried to use it like this: 我试图这样使用它:
myModel.removeRows(1, 1)
But I am getting thie error: 但是我得到了错误:
qrc:/Logger.qml:63: TypeError: Property 'removeRows' of object QStringListModel(0x337350) is not a function
Can someone explain how to use removeRows correctly? 有人可以解释如何正确使用removeRows吗? Thanks.
谢谢。
removeRows()
is not invokable from QML. 无法从QML调用
removeRows()
。 the solution is to make it invokable by creating a new class and overriding that method: 解决方案是通过创建一个新类并覆盖该方法使其可调用:
class StringListModel: public QStringListModel{
Q_OBJECT
public:
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()){
return QStringListModel::removeRows(row, count, parent);
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.