QAbstractListModel attempting to reference a deleted function
-
Hi!
I create classclass MarkerModel : public QAbstractListModel { Q_OBJECT public: using QAbstractListModel::QAbstractListModel; enum MarkerRoles{positionRole = Qt::UserRole + 1, idRole}; MarkerModel(); MarkerModel(const MarkerModel & refModel); ~MarkerModel(); bool operator != (MarkerModel const & refModel) {return !(m_ids == refModel.m_ids);} bool operator == (MarkerModel const & refModel) {return (m_ids == refModel.m_ids);} // Q_INVOKABLE void addMarker(const QGeoCoordinate &coordinate); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QHash<int, QByteArray> roleNames() const; public slots: void addMarker(const int &id, const QGeoCoordinate &coordinate); private: QList<QGeoCoordinate> m_coordinates; QList<int> m_ids; };
And when I want add object MarkerModel in QMap, then I get error:
QAbstractListModel attempting to reference a deleted function /:\QtProjects\qsingleteleshell\BModules\mmTerminal\backend\client.cpp:55: ошибка: C2280: 'MarkerModel &MarkerModel::operator =(const MarkerModel &)': attempting to reference a deleted function ..\..\..\qsingleteleshell\BModules\mmTerminal\backend\client.cpp(55): error C2280: 'MarkerModel &MarkerModel::operator =(const MarkerModel &)': attempting to reference a deleted function C:\QtProjects\qsingleteleshell\BModules\mmTerminal\backend\markermodel.h(36): note: compiler has generated 'MarkerModel::operator =' here C:\QtProjects\qsingleteleshell\BModules\mmTerminal\backend\markermodel.h(36): note: 'MarkerModel &MarkerModel::operator =(const MarkerModel &)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'QAbstractListModel &QAbstractListModel::operator =(const QAbstractListModel &)' C:\Qt\5.15.2\msvc2019_64\include\QtCore/qabstractitemmodel.h(434): note: 'QAbstractListModel &QAbstractListModel::operator =(const QAbstractListModel &)': function was explicitly deleted
-
Hi!
I create classclass MarkerModel : public QAbstractListModel { Q_OBJECT public: using QAbstractListModel::QAbstractListModel; enum MarkerRoles{positionRole = Qt::UserRole + 1, idRole}; MarkerModel(); MarkerModel(const MarkerModel & refModel); ~MarkerModel(); bool operator != (MarkerModel const & refModel) {return !(m_ids == refModel.m_ids);} bool operator == (MarkerModel const & refModel) {return (m_ids == refModel.m_ids);} // Q_INVOKABLE void addMarker(const QGeoCoordinate &coordinate); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QHash<int, QByteArray> roleNames() const; public slots: void addMarker(const int &id, const QGeoCoordinate &coordinate); private: QList<QGeoCoordinate> m_coordinates; QList<int> m_ids; };
And when I want add object MarkerModel in QMap, then I get error:
QAbstractListModel attempting to reference a deleted function /:\QtProjects\qsingleteleshell\BModules\mmTerminal\backend\client.cpp:55: ошибка: C2280: 'MarkerModel &MarkerModel::operator =(const MarkerModel &)': attempting to reference a deleted function ..\..\..\qsingleteleshell\BModules\mmTerminal\backend\client.cpp(55): error C2280: 'MarkerModel &MarkerModel::operator =(const MarkerModel &)': attempting to reference a deleted function C:\QtProjects\qsingleteleshell\BModules\mmTerminal\backend\markermodel.h(36): note: compiler has generated 'MarkerModel::operator =' here C:\QtProjects\qsingleteleshell\BModules\mmTerminal\backend\markermodel.h(36): note: 'MarkerModel &MarkerModel::operator =(const MarkerModel &)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'QAbstractListModel &QAbstractListModel::operator =(const QAbstractListModel &)' C:\Qt\5.15.2\msvc2019_64\include\QtCore/qabstractitemmodel.h(434): note: 'QAbstractListModel &QAbstractListModel::operator =(const QAbstractListModel &)': function was explicitly deleted
-
@Mihaill has nothing to do with QAbstractListModel.
In general you CAN NOT COPY a QObject, thats by design.you can only copy the pointer to a QObject
-
@J-Hilk
Absolutely true. But I do not see any attempt to assign/copy in any of the code shown by the OP. Are you saying the error arises because elsewhere he is trying to copy hisMarkerModel
?@JonB said in QAbstractListModel attempting to reference a deleted function:
Are you saying the error arises because elsewhere he is trying to copy his MarkerModel?
absolutely, it says so on the error log:
MarkerModel &MarkerModel::operator =(const MarkerModel &)': attempting to reference a deleted function
referenced here:
\QtProjects\qsingleteleshell\BModules\mmTerminal\backend\client.cpp:55:
that said, this:
MarkerModel(const MarkerModel & refModel);
is a copy constructor, also not allowed
-
@JonB said in QAbstractListModel attempting to reference a deleted function:
Are you saying the error arises because elsewhere he is trying to copy his MarkerModel?
absolutely, it says so on the error log:
MarkerModel &MarkerModel::operator =(const MarkerModel &)': attempting to reference a deleted function
referenced here:
\QtProjects\qsingleteleshell\BModules\mmTerminal\backend\client.cpp:55:
that said, this:
MarkerModel(const MarkerModel & refModel);
is a copy constructor, also not allowed
@J-Hilk said in QAbstractListModel attempting to reference a deleted function:
MarkerModel(const MarkerModel & refModel);
Got it, thanks!