0
votes

I am doing a project, basically what I want to do is to synchronize a property theProperty between 2 boxes in 2 QML files(2 boxes both own that property), I bind theProperty to a C++ Q_PROPERTY, so by binding the 2 boxes to the same C++ Q_PROPERTY, the synchronization can be achieved. Here are my codes in Box A and B. theProperty can be independently changed by Box A and B

Box_A {
    id: box_A
    // sth
    Binding { target:box_A; property: "theProperty"; value:model.CppModel.theProperty } 
    onThePropertyChanged: {
        model.CppModel.theProperty = theProperty
    }
}
Box_B {
    id: box_B
    // sth
    Binding { target:box_B; property: "theProperty"; value:model.CppModel.theProperty } 
    onThePropertyChanged: {
        model.CppModel.theProperty = theProperty
    }
}

In cpp:

    Class Item: QObject{
        Q_OBJECT
        Q_PROPERTY(bool theProperty READ theProperty WRITE theProperty NOTIFY theProperty Changed)
  //sth
        }

Within Box_A and B, there is a mouse area by which the theProperty can be changed:

MouseArea{

  onClicked: theProperty=!theProperty
}

The problem is that once I change theProperty in either box A or B, the qt creator complains that loop binding detected for value: model.CppModel.theProperty at the other side, is there a way of walking around this problem?

1

1 Answers

0
votes

Why don't you just do:

Box_A {
    id: box_A
    // sth
    theProperty:model.CppModel.theProperty  
}

Did that not work for you?