Muhammadxon Maxmudov
Muhammadxon Maxmudov

Reputation: 11

undefined reference to "_imp____class name ____ virtual method" On Qt 5.14.1 with QAbstractTableModel

everyone. Sorry for my English. I know English a little. I've a unsual problem. I've created AbstractModel inherited from QAbstractTableModel and MyAdvModel inherited from AbstractModel. This is my code partially.

// abstactmodel.hpp

#pragma once

#include <QAbstractTableModel>
#include "db/utility.hpp"
#include "net/serverloader.hpp"

class QNetworkReply;
class AbstractModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    virtual void parseData(QByteArray*) = 0;
    enum Error{NoError = 0, Null, NoFound, BadJson, NoServerConnection, Unknown};
    explicit AbstractModel(QObject *parent = nullptr);
    void setUrl(const QString&);
    void clearParams();
    void addParam(const QString&, const QVariant&);
    void delParam(const QString&);
    void post();
    void get();
protected:
    ServerLoader* server() const;
private slots:
    void response(QNetworkReply*);
private:
    unique_ptr<ServerLoader> _loader;
    unique_ptr<QVariantMap> _params;
};

// myadvmodel.hpp

#pragma once

#include "models/abstractmodel.hpp"
#include <QAbstractTableModel>
#include <tuple>
#include <vector>
#include <map>

class MyAdvModel :public AbstractModel
{
    Q_OBJECT

public:

    static constexpr auto ID_FIELD          = 0;
    static constexpr auto TYPE_FIELD        = 1;
     static constexpr auto ISCLOSED_FIELD    = 2;
//    static constexpr auto ISARRIVED_FIELD   = 3;
    static constexpr auto DATA_FIELD        = 3;
    static constexpr auto STATUS            = 0;
    static constexpr auto LAST              = 6;
    static constexpr auto COLUMNS           = 7;
    enum Type {Driver, Passanger};
    qint32 ID, MAX_ID;
    //                                    id       p/d     isc   isa   datas
    using data_t = std::vector<std::tuple<int32_t, Type, bool,/* bool,*/ std::map<QString, QVariant>>>;
    explicit MyAdvModel(QObject *parent = nullptr);
    ~MyAdvModel() override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    bool setData(const QModelIndex &index, const QVariant &value,
                 int role = Qt::EditRole) override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    Qt::ItemFlags flags(const QModelIndex& index) const override;
private:
    std::unique_ptr<data_t> _data, _tmp;
private slots:
    void parsed();
public:
    void parseData(QByteArray *) override;
};

on compiling time. I get error like this.

myadvmodel.o:myadvmodel.cpp:(.text+0x1225): undefined reference to > `_imp___ZNK18QAbstractItemModel4dataERK11QModelIndexi' collect2.exe: error: ld returned 1 exit status mingw32-make: *** [Makefile:182: up_desktop.exe] Error 1 20:38:38: Процесс «C:\Qt\Tools\mingw730_32\bin\mingw32-make.exe» завершился с кодом 2. Ошибка при сборке/развёртывании проекта up_desktop (комплект: Desktop MinGW_32) Во время выполнения этапа «Сборка»

Thanks for everyone who help me. again sorry for my english.

Upvotes: 1

Views: 155

Answers (2)

Muhammadxon Maxmudov
Muhammadxon Maxmudov

Reputation: 11

Thanks for all. I've solved this problem.

in my myadvmodel.cpp file

in implementation

QVariant MyAdvModel::data(const QModelIndex &index, int role) const
{
//......
   return AbstractModel::data(index, role);
//......
}

this is my error. in my AbstractModel class i've not wrote implementation for data method. in this situation my compiler gived me error for this code AbstractModel::data(index, role);. :) thanks for all, adn sorry for my english.

Upvotes: 0

Nikos C.
Nikos C.

Reputation: 51910

QAbstractItemModel is an abstract base class. When subclassing it, all pure virtual functions need to be implemented in at least one of the subclasses. In this case, the linker is complaining about the missing data() function, which is pure virtual (= 0).

So implement that and all the other pure virtual functions (like columnCount(), index(), parent(), etc.)

Upvotes: 1

Related Questions