Don't use -1 to query an index. It will return an invalid index.
ModelData->insertRows(0, 1);
ModelData->setData( ModelData->index(0), &addMe, Qt::DisplayRole);
ModelData->insertRows(0, 1);
ModelData->setData( ModelData->index(0), &addMe, Qt::DisplayRole);
To copy to clipboard, switch view to plain text mode
Also, I'm afraid there is something wrong with the way the custom struct is passed around:
void CParamDialog::on_ButtonAdd_clicked()
{
Model::XianStruct addMe;
...
ModelData->setData(..., &addMe, ...);
}
{
...
XianStruct newData = value.value<XianStruct>();
...
}
void CParamDialog::on_ButtonAdd_clicked()
{
Model::XianStruct addMe;
...
ModelData->setData(..., &addMe, ...);
}
bool Model::setData(const QModelIndex &index, const QVariant &value, int role )
{
...
XianStruct newData = value.value<XianStruct>();
...
}
To copy to clipboard, switch view to plain text mode
Notice that you are passing a pointer but then you're expecting it to be a value.
Bookmarks