Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. writing to an existing item within a C++ model to update QML listview
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 718 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.
  • saitejS Offline
    saitejS Offline
    saitej
    wrote on last edited by
    #1

    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
    0
    • V Offline
      V Offline
      Vicky Sharma
      wrote on last edited by
      #2

      @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
      0

      • Login

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