我有var results = [{body: 'Hi', userfrom_id: 'abc'}, {body: 'Hi', userfrom_id: 'xyz'}, {body: 'Hi', userfrom_id: 'abc'}]; //this is your result from database
var currUser_id = 'abc'; //this is current user
//loop
results.forEach(function(packet){if(packet.userfrom_id == currUser_id){console.log('my packet');}else{console.log('other user packet')}});
的子类名为QAbstractListModel
,其中包含方法ObjectListModel
:
remove()
但是,当我尝试从QML中调用class ObjectListModel : public QAbstractListModel
{
public:
Q_INVOKABLE void remove(int index);
}
时,我收到以下错误:
remove()
我通过TypeError: Property 'remove' of object QAbstractListModel(0x13c3c0) is not a function
:
ObjectListModel
的实例
MyApplication
我在Q_PROPERTY(ObjectListModel *uploadModel
MEMBER _uploadModel
NOTIFY uploadModelChanged)
:
main()
知道这里发生了什么吗?
答案 0 :(得分:1)
缺少Q_OBJECT
宏。
答案 1 :(得分:1)
您错过了Q_OBJECT
宏。
此外,您注册错误,需要以下内容:
qmlRegisterType<List>("ModuleName", 1, 0, "ObjectListModel");
QObject
是隐式元类型,因为它们得到了moc处理(如果你不忘记宏)。因此,无需将它们注册为元类型。