[QAbstractListModel 상속 클래스 만들시 유의사항]

Posted by 알거없어요
2014. 12. 24. 10:53 Error Report/QT

ListView 관련해서 QT에서 제공하는 클래스인 QAbstractListModel 를 상속받아서 클래스를 만들 경우 유의 해야 할점


클래스만 만들어서 빌드를 할 경우 qml에 로케이션이 안된다고 에러가 뜬다.




In file included from /opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQml/qqml.h:45:0,

                 from /opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQml/QtQml:9,

                 from /opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQuick/QtQuickDepends:4,

                 from /opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQuick/QtQuick:3,

                 from main.cpp:4:

/opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQml/qqmlprivate.h: In instantiation of 'void QQmlPrivate::createInto(void*) [with T = DVDListModel]':

/opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQml/qqml.h:227:5:   required from 'int qmlRegisterType(const char*, int, int, const char*) [with T = DVDListModel]'

main.cpp:29:66:   required from here

/opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQml/qqmlprivate.h:94:37: error: cannot allocate an object of abstract type 'QQmlPrivate::QQmlElement<DVDListModel>'

     void createInto(void *memory) { new (memory) QQmlElement<T>; }

                                     ^

/opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQml/qqmlprivate.h:85:11: note:   because the following virtual functions are pure within 'QQmlPrivate::QQmlElement<DVDListModel>':

     class QQmlElement : public T

           ^

In file included from /opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtCore/QtCore:49:0,

                 from /opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQuick/QtQuickDepends:2,

                 from /opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtQuick/QtQuick:3,

                 from main.cpp:4:

/opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtCore/qabstractitemmodel.h:181:17: note:       virtual int QAbstractItemModel::rowCount(const QModelIndex&) const

     virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;

                 ^

/opt/poky/1.6.2/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtCore/qabstractitemmodel.h:185:22: note:       virtual QVariant QAbstractItemModel::data(const QModelIndex&, int) const

     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;

                      ^

make: *** [main.o] Error 1


해결 방법은 간단하다


rowCount()와 data()를 함수를 만들어주면 해결된다.


위의 클래스를 사용하고 싶다면 필수적으로 위의 두개의 함수를 만들어야 한다는 룰이 있다는 점만 기억하자


내용은 QT Asistant를 찾아보면 관련 내용을 확인할 수 있다.