Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

error: use of deleted function while implementing listview



  • Hi
    I am implementing a listview inherited from QAbstractListModel.
    Am getting error like "use of deleted function ‘VEN_UI::Model::PackageModel& VEN_UI::Model::PackageModel::operator=(const VEN_UI::Model::PackageModel&)"
    Here is my code
    #include "inc/packagemodel.h"
    using namespace VEN_UI::Model;

                                          PackageDetails::PackageDetails(const QString &name, const QString &version)
                                              : m_pkgName(name), m_pkgVersion(version)
                                          {
                                          }
                                          
                                          QString PackageDetails::pkgName() const
                                          {
                                              return m_pkgName;
                                          }
                                          
                                          QString PackageDetails::pkgVersion() const
                                          {
                                              return m_pkgVersion;
                                          }
                                          
                                          PackageModel::PackageModel(QObject *parent)
                                              : QAbstractListModel(parent)
                                          {
                                          }
                                          
                                          void PackageModel::addPackage(PackageDetails* pkgDetails)
                                          {
                                              beginInsertRows(QModelIndex(), rowCount(), rowCount());
                                              m_pkgDetails.append(pkgDetails);
                                              endInsertRows();
                                          }
                                          
                                          int PackageModel::rowCount(const QModelIndex & parent) const {
                                              Q_UNUSED(parent);
                                              return m_pkgDetails.count();
                                          }
                                          
                                          QVariant PackageModel::data(const QModelIndex & index, int role) const {
                                              if (index.row() < 0 || index.row() >= m_pkgDetails.count())
                                                  return QVariant();
                                          
                                              PackageDetails* pkgDetails = m_pkgDetails[index.row()];
                                              if (role == NameRole)
                                                  return pkgDetails->pkgName();
                                              else if (role == VersionRole)
                                                  return pkgDetails->pkgVersion();
                                              return QVariant();
                                          }
                                          
                                          //QHash<int, QByteArray> PackageModel::roleNames() const {
                                          //    QHash<int, QByteArray> roles;
                                          //    roles[NameRole] = "name";
                                          //    roles[VersionRole] = "version";
                                          //    return roles;
                                          //}

  • Lifetime Qt Champion

    @drd1988on In which line do you get this error?
    You seem to assign PackageModel somewhere and assignment operator is disabled (deleted).


Log in to reply