Qt World Summit: Register Today!

Issue with Qt Controls signals inside ListView

  • Hi,

    I'm trying to make a ListView of Controls (Sliders, Checkboxes, ...) and I use a QAbstractListModel to populate the slide values and checkbox states.

    However, when a data update comes from the Model, the onValueChanged and onCheckedChanged in QML are called, and I need to know if the change has been made by the user or by the Model.

    Is there any way to block these signals when it's being updated by the model ?

    Thanks !

  • Do you see where in your C++ code emits valueChanged and checkedChanged?

  • Yes but the model should always notify changes. The problem is that in QML, using the ListView, the controller which updates the values when the model is updated is "invisible" by the developer.

    Anyways I have found a solution for the Sliders (I haven't tested for the checkboxes yet). I just add this in the onValueChanged :

    My fear was that, if the model is updated while the user presses the slider, it will bypass the if and override the value. Luckily QML blocks any value change signals while the user presses the slider, so it "magically" works but it's a bit of speculation.

  • Did you try "bool QObject::blockSignals(bool block)" ?

Log in to reply