Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. subclassing QAbstractTableModel
Forum Updated to NodeBB v4.3 + New Features

subclassing QAbstractTableModel

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 992 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    When I subscass what should I call in data() for other cases than Qt::DisplayRole

    class TSimpleTM: public QAbstractTableModel
    {public:
        virtual QVariant data(const QModelIndex & index,
                                int role = Qt::DisplayRole) const override
        {
            if(role != Qt::DisplayRole)
               // return QVariant();
                QAbstractTableModel::data(index, role);
                ...............
        }
    };
    

    For this code I get the stranger linker errror:
    TLDBAdmin_Form.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class QVariant __thiscall QAbstractItemModel::data(class QModelIndex const &,int)const " (_imp?data@QAbstractItemModel@@UBE?AVQVariant@@ABVQModelIndex@@H@Z) referenced in function "public: virtual class QVariant __thiscall TSimpleTM::data(class QModelIndex const &,int)const " (?data@TSimpleTM@@UBE?AVQVariant@@ABVQModelIndex@@H@Z)

    Must I fill all other roles other than Display too or can I give in all other cases the invalid QVariant to return?
    I yes, I cannot really understand how the defaults work for the other rules.

    HarbH 1 Reply Last reply
    0
    • Andy314A Andy314

      When I subscass what should I call in data() for other cases than Qt::DisplayRole

      class TSimpleTM: public QAbstractTableModel
      {public:
          virtual QVariant data(const QModelIndex & index,
                                  int role = Qt::DisplayRole) const override
          {
              if(role != Qt::DisplayRole)
                 // return QVariant();
                  QAbstractTableModel::data(index, role);
                  ...............
          }
      };
      

      For this code I get the stranger linker errror:
      TLDBAdmin_Form.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class QVariant __thiscall QAbstractItemModel::data(class QModelIndex const &,int)const " (_imp?data@QAbstractItemModel@@UBE?AVQVariant@@ABVQModelIndex@@H@Z) referenced in function "public: virtual class QVariant __thiscall TSimpleTM::data(class QModelIndex const &,int)const " (?data@TSimpleTM@@UBE?AVQVariant@@ABVQModelIndex@@H@Z)

      Must I fill all other roles other than Display too or can I give in all other cases the invalid QVariant to return?
      I yes, I cannot really understand how the defaults work for the other rules.

      HarbH Offline
      HarbH Offline
      Harb
      wrote on last edited by Harb
      #2

      @Andy314 Hi!
      No, you don't have to fill all other roles. Just write

      return QVariant() ;
      

      at the end of your reimplemented data() function.
      UPD.
      As I understand It works this way. Model inform View each time when data updated. View call data() function for each item, that were updated, if it get data for specific role, it displays it in a proper way, if it gets QVariant() it just doesn't display anything, or display it in default way. For example each item in QTableView may have small icon. But if you don't implement data() for Qt::DecorationRole view just will not show it. On the other hand if you don't implement data() for Qt::FontRole, view will display data with default font.

      As for linker error, have no ideas. Tried your code, and didn't get any linker error. Just try to clean project, it is the first thing I do when I get ANY linker error : )

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved