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. [SOLVED] unresolved external symbol

[SOLVED] unresolved external symbol

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k Views
  • 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 Offline
    G Offline
    great88
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      great88
      wrote on last edited by
      #2

      Does this compile for anyone ?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hisoft
        wrote on last edited by
        #3

        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
        0
        • G Offline
          G Offline
          great88
          wrote on last edited by
          #4

          Thank you ! That works .

          1 Reply Last reply
          0
          • qwasder85Q Offline
            qwasder85Q Offline
            qwasder85
            wrote on last edited by
            #5

            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
            2

            • Login

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