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. How to update C++ QAbstractListModel properly
Qt 6.11 is out! See what's new in the release blog

How to update C++ QAbstractListModel properly

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 411 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
    MattC24
    wrote on last edited by MattC24
    #1

    Hello,
    I'm currently working on refactoring/fixing some code. I have an issue I need help figuring out. I'm trying to figure out the best way to update the model/view once I get updated values from our backend application. The model handles Setting Objects. I have a client class that receives the parameter and its new value then goes to propagates that to a SettingsManager class. SettingsManager checks the new value coming in and saves it. Once that's saved what's the best way to update the model? Should I just create a signal to connect to SetData()?

    void SettingsManager::setValue(const QVariant& value, int setting)
    {
        SettingBase *SB = allSettingsMap.value(setting);
        if(SB != nullptr){
            qDebug()<<" Updating setting: " << setting  <<" in map to " << value;
             //allSettingsMap.value(setting)->setTempValue(value); // set temp value equal to value
             SB->setTempValue(value);
             SB->saveValue();
             qDebug()<<" Setting Map Updated to " << value;
             emit settingValueChanged(setting, value);
        }
    }
    

    Would I just connect settingValueChanged to setData? And I'd need some function to calculate QModelIndex which gets tricky because I have multiple vectors of settings (One vector for each page of settings). Does anyone have a suggestion of how to update? To combat the current implementation has a bunch of signals emitting in the client and having qml connection types on the different qml pages. (See below)

    if (paramName == QString("ampRating")) {settingmanager->setSettingValue(Settings::Parameter::AmpRating,value); emit updateTSModel(26,QVariant(value).toString(), 2);
    

    On that page then:

        Connections {
            target: client
            onUpdateTSModel:{
                console.log("SettingList.SetData()" + " index: " + m_idx + " value: " + m_value)
                mList.setData(mList.index(m_idx,0,mList), m_value, 259)
            }
        }
    
    
    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