1

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

誰かが私が間違っていることを知っていますか?

ありがとう!

4

1 に答える 1

1

うまくいきました:

cpp ファイルを削除staticして、正しいクラス識別子を追加する必要がありました。

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

于 2013-12-31T11:17:06.603 に答える