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. QAbstractListModel attempting to reference a deleted function
Forum Updated to NodeBB v4.3 + New Features

QAbstractListModel attempting to reference a deleted function

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 959 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.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by
    #1

    Hi!
    I create class

    class 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
    
    
    J.HilkJ 1 Reply Last reply
    0
    • M Mihaill

      Hi!
      I create class

      class 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
      
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      JonBJ 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @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 his MarkerModel?

        J.HilkJ 1 Reply Last reply
        0
        • JonBJ JonB

          @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 his MarkerModel?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @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


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          JonBJ 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @J-Hilk said in QAbstractListModel attempting to reference a deleted function:

            MarkerModel(const MarkerModel & refModel);
            

            Got it, thanks!

            1 Reply Last reply
            0

            • Login

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