0

I have interface class IHistory. And i want to implement QAbstractTableModel. My code invoke undefined reference to vtable error, and it's doesn't fix by running qmake.

(ihistory.h)

class IHistory: public QAbstractTableModel
{
    ...
    // QAbstractItemModel interface
public:
    virtual int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE ;
    virtual int columnCount(const QModelIndex &parent) const Q_DECL_OVERRIDE ;
    virtual QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE ;
    virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE ;
    ...
};

In child class i wrote (history.h):

class History : public IHistory
{
    //Q_OBJECT
    Q_INTERFACES(IHistory)

public:
    History();
    ~History();

    ...
    // QAbstractItemModel interface
public:
    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
    ...
};

Is there a right way, or i should implement QAbstractTableModel in class History?

murzagurskiy
  • 1,273
  • 1
  • 20
  • 44

1 Answers1

0

I found right way! Just delete redefining in interface, and add implementation of all abstract functions in history.cpp.

So, something like rule:

If you want to inherit in interface class from other interface in QT, just do it like usual: class IFoo: public IBar. Then, when you implement interface IFoo:

1) Inherit from interface: class Foo: public IFoo

2) Press Alt + Enter and choose Insert virtual methods of base classes

3) Then, for each methods use Alt + Enter and choose Implement (methodname) in class Foo.cpp

4) Profit!

murzagurskiy
  • 1,273
  • 1
  • 20
  • 44