1

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

有谁知道我做错了什么?

谢谢!

4

1 回答 1

1

得到它的工作:

必须在 cpp 文件中删除static并添加正确的类标识符:

void NoteList::append(QQmlListProperty<Note> *property, Note* value)

于 2013-12-31T11:17:06.603 回答