Important: Please read the Qt Code of Conduct -

[SOLVED] unresolved external symbol

  • 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

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

    class SqlQueryModel : public QSqlQueryModel {


    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);

  • Does this compile for anyone ?

  • Hi,

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

    with this one :

    return QSqlQueryModel::data(item, role);

    it will compile !

  • Thank you ! That works .

  • 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.

Log in to reply