【问题标题】:Error when trying to set up a QQmlListProperty尝试设置 QQmlListProperty 时出错
【发布时间】:2013-12-31 19:17:06
【问题描述】:

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

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

谢谢!

【问题讨论】:

    标签: c++ qt5 sailfish-os


    【解决方案1】:

    搞定了:

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

    void NoteList::append(QQmlListProperty&lt;Note&gt; *property, Note* value)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      • 2018-11-22
      • 2013-05-20
      • 1970-01-01
      相关资源
      最近更新 更多