[SOLVED]Linker error for custom QListModel
-
Hi, everybody!
I
ve got a disgusting error: @undefined reference to
QAbstractItemModel::data(QModelIndex const&, int) const'@
while trying to write custom model that inherits QAbstractListModel :(
Here is the code:MusicListModel.h
@#include <QAbstractListModel>
#include <QStringList>
#include <QBrush>
#include <QHash>
#include <QAbstractItemModel>
class MusicListModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit MusicListModel(QObject *parent = 0);bool setData(const QModelIndex &index, const QVariant &value, int role); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; int rowCount(const QModelIndex&) const; void setNamesList(QStringList &lst); void setPathesList(QStringList &lst);
private:
QStringList namesList;
QStringList pathesList;
QHash<int, QBrush> color;};
@MusicListModel.cpp
@#include "musiclistmodel.h"MusicListModel::MusicListModel(QObject *parent) :
QAbstractListModel(parent)
{
}bool MusicListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if(index.row() < 0 || index.row() >= nameList.size())
return false;switch(role) { case Qt::DisplayRole: nameList.replace(index.row(), value.toString()); return true; break; case Qt::ToolTipRole: if(index.row() >= 0 && index.row() < pathList.size()) { pathList.replace(index.row(), value.toString()); return true; } return false; break; case Qt::BackgroundRole: color.insert(index.row(), QBrush(value.value<QColor>(), Qt::LinearGradientPattern)); return true; break; default: return false; }
}
QVariant MusicListModel::data(const QModelIndex &index, int role) const
{
if(index.row() < 0 || index.row() >= nameList.size())
return QVariant();switch(role) { case Qt::DisplayRole: return namesList.at(index.row()); break; case Qt::ToolTipRole: return pathesList.at(index.row()) ; break; case Qt::BackgroundRole: return color.value(index.row(), QBrush(Qt::white)); break; default:
===> return QAbstractListModel::data(index, role);
}
}int MusicListModel::rowCount(const QModelIndex & /&parent/) const
{
return namesList.size();
}
@I can
t understand why this subroutine isn
t seen by compiler.
Please, help me to correct it. -
Hi, you should have note that, it's a pure virtual member of QAbstractItemModel.
@
QVariant QAbstractItemModel::data(const QModelIndex & index, int role = Qt::DisplayRole) const [pure virtual]
@BTW, If you do not have a value to return, return an invalid QVariant.