Error when trying to set up a QQmlListProperty

1k views Asked by At

I'm building a simple Sailfish OS app using C++ and QML. I'm trying to expose my database layer to QML via a QQmlListProperty - however I'm running into problems. I've probably set it up wrong - but I can't figure out where.

This is my setup code:

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

These are the actual methods I'm trying to pass in to the list property:

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);
}

When I compile - I get this:

/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

Does anyone have any idea what I'm doing wrong?

Thanks!

1

There are 1 answers

0
Malakim On BEST ANSWER

Got it working:

Had to remove static in the cpp file and add the correct class identifier:

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