A little question, I used QAbstractListModel for providing data to QML properties, the first 2 string properties assignments were OK, but when I tried to assign a bool QML property, the assignment failed. My codes are like the following:
ListView
model: MyModel
delegate:
MyItem {
test: MyModel.isRunning //test is the bool property and isRunning is the bool role in MyModel
MouseArea{
anchors.fill: parent
onClicked: {
MyModel.setisRunning(index,boolFlag) //invert MyModel.isRunning
}
}
In MyModel Class I have the following related codes:
void MyModel::setisRunning(int itemIndex, bool isRunning)
{
mItem[itemIndex]->setRunningState(isRunning);
emit dataChanged(index(itemIndex,2), index(itemIndex,2),QVector<int>() << TimerRole);
}
and in MyItem Class I have the following related codes:
void MyItem::setRunningState(bool isRunning)
{
if(isRunning!=m_isRunning)
{
m_isRunning = isRunning;
}
}
I couldn't invert the test property's bool state after I changed MyModel.isRunning, test property always showed "false" when I printed it out.
What confused me most was by executing TimerModel.setisRunning(index,boolFlag), MyModel.isRunning can switch between true/ false, but test property cannot change accordingly
I am new to Qt, please help me out! Thank you