我正在使用C ++和QML构建一个简单的Sailfish OS应用程序。 我试图通过QQmlListProperty将我的数据库层暴露给QML - 但是我遇到了问题。我可能设置错了 - 但我无法弄清楚在哪里。
这是我的设置代码:
QQmlListProperty<Note> NoteList::notes() {
return QQmlListProperty<Note>(this, &_notes, &append, &size, &at, &clear);
}
这些是我尝试传递给list属性的实际方法:
static void append(QQmlListProperty<Note> *property, Note* value) {
NoteList *list = (NoteList*) property;
list->addNote(value);
}
static void clear(QQmlListProperty<Note> *property) {
NoteList *list = (NoteList*) property;
list->clearNotes();
}
static int size(QQmlListProperty<Note> *property) {
NoteList *list = (NoteList*) property;
return list->countNotes();
}
static Note* at(QQmlListProperty<Note> *property, int index) {
NoteList *list = (NoteList*) property;
return list->noteAt(index);
}
当我编译时 - 我明白了:
/Users/markus/Documents/SailfishOS/build-SilicaNote-MerSDK_SailfishOS_i486_x86-Debug/notelist.o:-1: In function `QQmlListProperty'
/usr/include/qt5/QtQml/qqmllist.h:72: error: undefined reference to `NoteList::append(QQmlListProperty<Note>*, Note*)
File not found: /usr/include/qt5/QtQml/qqmllist.h
/usr/include/qt5/QtQml/qqmllist.h:72: error: undefined reference to `NoteList::at(QQmlListProperty<Note>*, int)'
File not found: /usr/include/qt5/QtQml/qqmllist.h
/usr/include/qt5/QtQml/qqmllist.h:72: error: undefined reference to `NoteList::clear(QQmlListProperty<Note>*)'
File not found: /usr/include/qt5/QtQml/qqmllist.h
:-1: error: collect2: ld returned 1 exit status
有谁知道我做错了什么?
谢谢!
答案 0 :(得分:1)
搞定了:
必须删除cpp文件中的static
并添加正确的类标识符:
void NoteList::append(QQmlListProperty<Note> *property, Note* value)