gpt4 book ai didi

c++ - 尝试设置 QQmlListProperty 时出错

转载 作者:太空宇宙 更新时间:2023-11-04 11:42:29 27 4
gpt4 key购买 nike

我正在使用 C++ 和 QML 构建一个简单的 Sailfish OS 应用程序。我正在尝试通过 QQmlListProperty 将我的数据库层公开给 QML - 但是我遇到了问题。我可能设置错了 - 但我不知道在哪里。

这是我的设置代码:

QQmlListProperty<Note> NoteList::notes() {
return QQmlListProperty<Note>(this, &_notes, &append, &size, &at, &clear);
}

这些是我试图传递给列表属性的实际方法:

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

有谁知道我做错了什么吗?

谢谢!

最佳答案

成功了:

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

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

关于c++ - 尝试设置 QQmlListProperty 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20835776/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com