1

I am facing a problem while developing my program. I have a QAbstractListModel which contain a boole property, and I want to be able to pass that value to my QML file containing a CheckBox.

I found this question on StackOverflow covering the same problem. I am facing the exact same problem but the question and answer cover the case where the property is sent to the qml through a Q_PROPERTY whereas I use a QAbstractListmodel. I have overridden the setData(), data() and flags() methods and all works fine but I have a button that check/uncheck all my CheckBoxes and if the user directly check one of them that one will not be editable through my check/uncheck button.

So basically, I want to know how to set up a bi-directional binding using a QAbstractListModel instead of a Q_PROPERTY.

Thank you.

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
David Gonzalez
  • 655
  • 3
  • 6
  • 25

1 Answers1

2

Sorry for bothering you. I just found out the answer using my very little brain for more than 5 minutes.

I just needed to use the dataChanged signal in order to be able to connect correctly my model to the view.

 CheckBox {
        id: myCheck
        onClicked: user.status = checked
        Component.onCompleted: checked = user.status
        Connections {
            target: user
            onDataChanged: myCheck.checked = user.status
        }
    }

Didn't know we could pass an existing signal directly to QML just putting on in front on the signal's name.

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
David Gonzalez
  • 655
  • 3
  • 6
  • 25
  • 1
    *Any* property, property as a corresponding changing handler, i.e. if you define a property `myProp` you can declare an handler `onMyProp` with the first letter uppercase. Same goes for signals. If the answer solved your problem just accept this as the correct answer, please. – BaCaRoZzo Mar 20 '15 at 09:24
  • 1
    To add to @BaCaRoZzo's comment, any custom-defined property must begin with a small letter. – Sнаđошƒаӽ Mar 20 '15 at 11:08
  • 2
    @BaCaRoZzo it's `onMyPropChanged` – GrecKo Mar 20 '15 at 11:18
  • Lol...obviously it is. Just lost it. Thanks to pointint it out. :) So it's `name` (first letter lowercase) for the signal/property and `onNameChanged` (first letter of property/signal uppercase) for the corresponding handler. – BaCaRoZzo Mar 20 '15 at 11:49