Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] unresolved external symbol

    General and Desktop
    3
    5
    1948
    Loading More Posts
    • 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.
    • G
      great88 last edited by

      I get error ( and see my code below ) :

      @SqlQueryModel.obj : 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 SqlQueryModel::data(class QModelIndex const &,int)const " (?data@SqlQueryModel@@UBE?AVQVariant@@ABVQModelIndex@@H@Z)@

      what am i doing wrong ?:

      header :
      @#ifndef SQLQUERYMODEL_H
      #define SQLQUERYMODEL_H

      #include <QSqlQueryModel>
      #include <QModelIndex>
      #include <QAbstractItemModel>

      class SqlQueryModel : public QSqlQueryModel {
      Q_OBJECT

      private:

      public:
      SqlQueryModel(QObject * parent = 0);
      QVariant data(const QModelIndex & item, int role ) const;
      public slots:

      };

      #endif // SQLQUERYMODEL_H@

      cpp :
      @#include "SqlQueryModel.h"

      SqlQueryModel::SqlQueryModel(QObject *parent) : QSqlQueryModel(parent) {

      }

      QVariant SqlQueryModel::data(const QModelIndex & item, int role ) const {
      if (item.column() == 1 && role == Qt::TextAlignmentRole) {
      return Qt::AlignRight;
      } else {
      return QAbstractTableModel::data(item, role);
      }
      }@

      1 Reply Last reply Reply Quote 0
      • G
        great88 last edited by

        Does this compile for anyone ?

        1 Reply Last reply Reply Quote 0
        • H
          hisoft last edited by

          Hi,

          if you replace this ligne code :
          @
          return QAbstractTableModel::data(item, role);
          @

          with this one :

          @
          return QSqlQueryModel::data(item, role);
          @

          it will compile !

          1 Reply Last reply Reply Quote 0
          • G
            great88 last edited by

            Thank you ! That works .

            1 Reply Last reply Reply Quote 0
            • qwasder85
              qwasder85 last edited by

              Just to clarify for future reference:

              QAbstractTableModel inherits from QAbstractItemModel, which only has a pure virtual data()-function. This means it does not have a default implementation of this function (it's "empty").
              Since QAbstractTableModel doesn't then implement data() either, you can't actually use it directly (it's still "empty").
              You can only inherit from QAbstractTableModel and then implement its functionality yourself. Or use a different class that comes with a working implementation of this function, as you did with QSqlQueryModel.

              1 Reply Last reply Reply Quote 2
              • First post
                Last post