我正在使用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

有人知道我在做什么错吗?

谢谢!

最佳答案

得到它的工作:

必须删除cpp文件中的static并添加正确的类标识符:
void NoteList::append(QQmlListProperty<Note> *property, Note* value)

09-08 00:13