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

QML model item text change - data is changing in c++ but not on screen (unless you flip to another screen and back)



  • I need to update current data (in this instance an download progress - list of items a user can download needs to have a progress by the ones currently downloading). So the items in the list should update as appropriate but you should still be able to up/down arrow on the list. The data is updated in the c++. If I update the whole list the up/down arrows do not work because the list is constantly being refreshed. The c++ is changing the data which emits the onChanged but nothing on screen changes.

    if I use this the screen refreshes constantly because there it is 'new' data so the QML resets the index (I assume)
    @
    getGuide()->updateQMLView(QVariant::fromValue(m_model));
    @

    The objects in my list are
    @
    class CDetails : public QObject
    {
    Q_OBJECT

    public:
    CDetails();
    ~CDetails(void);

    //QML properties
    

    Q_PROPERTY(QString displayText READ getQML_displayText WRITE setQML_displayText NOTIFY QML_displayTextChanged)
    QString getQML_displayText();
    void setQML_displayText(QString text);
    QString QML_displayText;

    ...
    signals:
    void QML_displayTextChanged();

    };
    @

    A breakpoint here shows the method is being called when expected
    @
    void CDetails::setQML_displayText(QString text)
    {
    QML_displayText = text;
    emit QML_displayTextChanged();
    }
    @



  • Could you show us how do you use it in QML?


Log in to reply