Results 1 to 5 of 5

Thread: Subclassing an Implementattion of QAbstractItemModel

  1. #1
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Subclassing an Implementattion of QAbstractItemModel

    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.

    Qt Code:
    1. class MyModel : public QAbstractItemModel
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyModel( const QString &filename, QObject* parent = 0 );
    7. ~MyModel();
    8.  
    9. /*
    10.   ** AbstractItemModel(required methods)
    11.   */
    12. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const;
    13. QModelIndex index(int row, int col, const QModelIndex &parent = QModelIndex() ) const;
    14. QModelIndex parent(const QModelIndex &index ) const;
    15. int rowCount(const QModelIndex &parent = QModelIndex() ) const;
    16. int columnCount(const QModelIndex &parent = QModelIndex() ) const;
    17. QVariant headerData(int section, Qt::Orientation orientation,
    18. int role = Qt::DisplayRole) const;
    19.  
    20. Qt::ItemFlags flags(const QModelIndex &index) const;
    21. bool setData(const QModelIndex &index, const QVariant &value,
    22. int role = Qt::EditRole);
    23. private:
    24. void setupModel();
    25. .
    26. .
    27. .
    28. };
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. class MyTXTModel : MyModel
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyTXTModel(const QString& filename, QObject *parent = 0);
    7. ~MyTXTModel();
    8.  
    9. private:
    10. .
    11. .
    12. .
    13. };
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. 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)".
    2. 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)".
    3. .
    4. .
    5. .
    To copy to clipboard, switch view to plain text mode 

    Does anybody have a solution for this problem???

    Kind regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Subclassing an Implementattion of QAbstractItemModel

    My guess is you didn't run qmake after adding the Q_OBJECT macro to the class declaration.

  3. #3
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Subclassing an Implementattion of QAbstractItemModel

    Hmmm that can't be the problem. I successfully ran qmake and moc_MyTXTModel.cpp is generated.

  4. #4
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing an Implementattion of QAbstractItemModel

    Have you provided a body for the constructor in a .cpp file?

  5. #5
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Subclassing an Implementattion of QAbstractItemModel

    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!

    But thanks anyway for your ideas guys!!!

Similar Threads

  1. Subclassing QAbstractItemModel
    By r366y in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2006, 08:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.