PDA

View Full Version : Howto reverse QVariant::fromValue(val)?



porterneon
3rd January 2012, 16:08
Hi
I'm creating qt c++ application with Qml GUI. In qml I have object with ListView to display in row object's properties. In header I have declared meta type:

Q_DECLARE_METATYPE(QList<QObject*>)
QList<QObject*> is being passed to Qml ListView model as slot parameter. User is able to change NewPrice value.


...
function setPriceDetails(model)
{
viewPriceDetails.myModel = model
}
...
ListView {
id: viewPriceDetails
onModelChanged: {
parent.height = viewCenyDetails.height + 130
}
model: myModel
delegate: Row {
Text { width: 10 }
Text { text: model.modelData.ItemNo; width: 10; }
Text { text: model.modelData.Description; width: 80; }
Text { text: model.modelData.ActualPrice; width: 80; }
MyTextInput {
text: model.modelData.NewPrice

onTextChanged: model.modelData.NewPrice= text
}
}
}
...
QList<QObject*> dataList;
while(queryCenaPaliw.next()){
dataList.append(new ActualPrice(queryCenaPaliw.value(queryCenaPaliw.re cord().indexOf("ItemNo")).toString(),
queryCenaPaliw.value(queryCenaPaliw.record().index Of("Description")).toString(),
queryCenaPaliw.value(queryCenaPaliw.record().index Of("ActualPrice")).toString()));
}

emit DB_AktualneCenyPaliw(QVariant::fromValue(dataList) );
On button click ListView model (myModel) is being send as signal parameter to c++ object

signal updatePrices(variant model)

...MenuButton {
id: btnUpdate
text: "Update"
height: 46

onButtonClicked: {
root.updatePrices(root.myModel)
}
}
...


Now question:
How to in c++ work with this model? I would like to use it to update my db data. How to access data in model?