Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    writing to an existing item within a C++ model to update QML listview

    QML and Qt Quick
    2
    2
    586
    Loading More Posts
    • 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.
    • saitej
      saitej last edited by

      Hi

      I am using a similar model as described here. I need to update the value of an existing item . So i guess i need to setdata() and then emit datachanged() signal (please do correct me if I am wrong!!). Can someone guide me how to write the setdata() function.

      This is what I have written:

      I need to change only the size values so I have added a setdata() in the Animal class also.

      Function I have added to Animal class:*

      void Animal::setData(const QString size, int role){
             if(role == AnimalModel::SizeRole)
              setsize(size);
          else
              return;
      }
      
      
      void Animal::  setsize(const QString size){
      
                    if(QString::compare(size,m_size,Qt::CaseInsensitive))
                             return;
          m_size = size;
      }
      
      void AnimalModel::setdata(const QModelIndex &index,const QString &type,const QString &size){
      
      Q_UNUSED(type)
      if (index.row() < 0 || index.row() >= m_animals.count())
                     return;
      
      m_animals.at(index.row()).setData(size,role);
      
      }
      

      I get the error in this line :

      error: passing 'const Animal' as 'this' argument of 'void Animal::setData(QString, int)' discards qualifiers [-fpermissive]
      m_animals.at(index.row()).setData(value,role);
      ^

      1 Reply Last reply Reply Quote 0
      • V
        Vicky Sharma last edited by

        @saitej
        You may refer this post to understand this error happening.

        http://stackoverflow.com/questions/5973427/error-passing-xxx-as-this-argument-of-xxx-discards-qualifiers

        1 Reply Last reply Reply Quote 0
        • First post
          Last post