PDA

View Full Version : Subclassing an Implementattion of QAbstractItemModel



ob019
17th April 2008, 15:38
Hello everybody,
i am a newbie in using the MVC-Classes of QT4. (4.3.4) I have got the following problem:

I provide an implementation of QAbstactItemModel named MyModel. This Model works fine.


class MyModel : public QAbstractItemModel
{
Q_OBJECT

public:
MyModel( const QString &filename, QObject* parent = 0 );
~MyModel();

/*
** AbstractItemModel(required methods)
*/
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const;
QModelIndex index(int row, int col, const QModelIndex &parent = QModelIndex() ) const;
QModelIndex parent(const QModelIndex &index ) const;
int rowCount(const QModelIndex &parent = QModelIndex() ) const;
int columnCount(const QModelIndex &parent = QModelIndex() ) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;

Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole);
private:
void setupModel();
.
.
.
};

Now I want to subclass from this bassclass to create a new model called MyTXTModel.


class MyTXTModel : MyModel
{
Q_OBJECT

public:
MyTXTModel(const QString& filename, QObject *parent = 0);
~MyTXTModel();

private:
.
.
.
};

But this model doesn't work. I get several errors from the linker:


MyTXTModel.obj : error LNK2019: link to unresolved external symbol ""public: __thiscall MyModel::MyModel(class QString const &,class QObject *)" (??0MyModel@@QAE@ABVQString@@PAVQObject@@@Z)" in function ""public: __thiscall MyTXTModel::MyTXTModel(class QString const &,class QObject *)" (??0MyTXTModel@@QAE@ABVQString@@PAVQObject@@@Z)".
MyTXTModel.obj : error LNK2001: unresolved external symbol ""public: virtual class QModelIndex __thiscall MyModel::index(int,int,class QModelIndex const &)const " (?index@MyModel@@UBE?AVQModelIndex@@HHABV2@@Z)".
.
.
.


Does anybody have a solution for this problem???

Kind regards

wysota
17th April 2008, 16:43
My guess is you didn't run qmake after adding the Q_OBJECT macro to the class declaration.

ob019
18th April 2008, 08:05
Hmmm that can't be the problem. I successfully ran qmake and moc_MyTXTModel.cpp is generated. :confused:

stevey
18th April 2008, 10:54
Have you provided a body for the constructor in a .cpp file?

ob019
21st April 2008, 14:36
Ahhh I found my fault!!!
I tried to use Qt's plugin-capabilities for extending my base-model.
So the base-class is in the core-application and the derived class is integrated by using a plugin. I forgot including the base-class to the plugin-project. Stupid error! :o

But thanks anyway for your ideas guys!!!