c++ - Undefined reference to class method which inherits from template which inherits from QAbstractItemModel -
i having difficulty getting derived classes function project working on.
the project using qt. using model-view architecture, , project has number of models, more or less model different business objects share lot of logic.
at moment, each model inherits qabstracttablemodel , functions satisfactorily. issue there duplication between these models, , prefer not repeat code multiple times.
therefore, have created generic base class, inherits qabstracttablemodel implements common functionality (adding rows databases, executing common business logic, retrieving header data). models views use inherit derived class, , implement table specific functionality (mainly getting , setting data objects represent data). generic base class provides part of functionality, , specific instances of model complete it.
so qabstracttablemodel -> qualityitemmodel -> (the various models views use).
qualityitemmodel have made template, shared code must work different types.
the issue getting following error after linking, when trying call these methods.
/home/user/program/project/ui/complaintsui.cpp:136: undefined reference `complaintsmodel::clear()' moc_complaintsmodel.o:(.data.rel.ro._ztv15complaintsmodel[_ztv15complaintsmodel]+0x70): undefined reference `complaintsmodel::index(int, int, qmodelindex const&) const' moc_complaintsmodel.o:(.data.rel.ro._ztv15complaintsmodel[_ztv15complaintsmodel]+0x88): undefined reference `complaintsmodel::rowcount(qmodelindex const&) const' moc_complaintsmodel.o:(.data.rel.ro._ztv15complaintsmodel[_ztv15complaintsmodel]+0x90): undefined reference `complaintsmodel::columncount(qmodelindex const&) const' moc_complaintsmodel.o:(.data.rel.ro._ztv15complaintsmodel[_ztv15complaintsmodel]+0xb0): undefined reference `complaintsmodel::headerdata(int, qt::orientation, int) const' moc_complaintsmodel.o:(.data.rel.ro._ztv15complaintsmodel[_ztv15complaintsmodel]+0x140): undefined reference `complaintsmodel::flags(qmodelindex const&) const'
complaints model inherits template, inherits qabstracttablemodel. oddly, other methods have added don't have error. template implemented in header file, issue isn't template code in .cpp file.
code follows. have omitted code in implementation brevity.
qualityitemmodel.h
#ifndef qualityitemmodel_h #define qualityitemmodel_h #include <qvector> #include <qabstracttablemodel> template <typename t> class qualityitemmodel : public qabstracttablemodel { public: explicit qualityitemmodel(qobject *parent = 0); qvariant headerdata(int section, qt::orientation orientation, int role) const; void remove(int row); int columncount(const qmodelindex &parent) const; qt::itemflags flags(const qmodelindex &index) const; qmodelindex index(int row, int column, const qmodelindex &parent) const; int rowcount(const qmodelindex &parent) const; void add(t c); void clear(); bool submit(); void junk(); protected: qvector<t> modelitemlist; int currentrow; int row; typename qvector<t>::const_iterator modelitemlistitr; typename qvector<t>::const_iterator begin() const { return modelitemlist.begin(); } typename qvector<t>::const_iterator end() const { return modelitemlist.end(); } }; template <typename t> qualityitemmodel<t>::qualityitemmodel(qobject *parent) : qabstracttablemodel(parent) { } template <typename t> qvariant qualityitemmodel<t>::headerdata(int section, qt::orientation orientation, int role) const { } template <typename t> void qualityitemmodel<t>::remove(int row) { } template <typename t> int qualityitemmodel<t>::columncount(const qmodelindex &parent) const { } template <typename t> qt::itemflags qualityitemmodel<t>::flags(const qmodelindex &index) const { } template <typename t> qmodelindex qualityitemmodel<t>::index(int row, int column, const qmodelindex &parent) const { } template <typename t> int qualityitemmodel<t>::rowcount(const qmodelindex &parent) const { } template <typename t> void qualityitemmodel<t>::add(t c) { } template <typename t> void qualityitemmodel<t>::clear() { } template <typename t> bool qualityitemmodel<t>::submit() { } template <typename t> void qualityitemmodel<t>::junk() {qdebug() << "junk";} #endif // qualityitemmodel_h
the code inherit template is
complaintsmodel.h
class complaintsmodel : public qualityitemmodel<complaint>
with constructor
complaintsmodel::complaintsmodel(qobject *parent) : qualityitemmodel(parent) { }
complaintsmodel implements 'data' , 'setdata' methods.
this used later in following fashion
complaintsmodel *model = new complaintsmodel(this); model->clear() // linker error model->junk() // no linker error
i suspect has fact qabstracttablemodel abstract class, i'm not quite sure how resolve issue.
the alternative template helper functions, rather entire class.
Comments
Post a Comment