yagabey
6th December 2014, 21:31
Hi , i have a problem with QStandardItemModel and QIdentityProxyModel.
I've implemented a QIdentityProxyModel to be able to change the way of displaying the model. Here is the data() function of QIdentityProxyModel :
QVariant data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole && index.column() == AlarmLogViewIndex_RecovTime){
qDebug()<< sourceModel()->data(index);
qint64 sinceEpoch = sourceModel()->data(index).toLongLong();
const QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(sinceEpoch);
return dateTime.toString(m_formatString);
}
}
This works like a charm when source model is a QSqlTableModel. But i need to use the same QIdentityProxyModel for a QStandardItemModel. When i use standartItemModel as the source of QIdentityProxyModel , i get QVariant(Invalid) values from the above data() function (in qDebug output...) . I was suspicious about the way i created the StandardItemModel. But it works well without the QIdentityProxyModel .
Here is how i implement the StandardItemModel,
adding a row to the model:
void TagChannelItemModel::addToTagModel(pEtiketDef_t tg)
{
int row = tagModel->rowCount();
QStandardItem* item = new QStandardItem(QString::number(tg.Id));
tagModel->setItem(row, TgIndex_Id, item);
item = new QStandardItem(tg.Name);
tagModel->setItem(row, TgIndex_Name, item);
item = new QStandardItem(QString::number(tg.PollFrequency));
tagModel->setItem(row, TgIndex_PollFreq, item);
}
Should i do anything else for this item model to work with ProxyModel ?
Thanks in advance...
I've implemented a QIdentityProxyModel to be able to change the way of displaying the model. Here is the data() function of QIdentityProxyModel :
QVariant data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole && index.column() == AlarmLogViewIndex_RecovTime){
qDebug()<< sourceModel()->data(index);
qint64 sinceEpoch = sourceModel()->data(index).toLongLong();
const QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(sinceEpoch);
return dateTime.toString(m_formatString);
}
}
This works like a charm when source model is a QSqlTableModel. But i need to use the same QIdentityProxyModel for a QStandardItemModel. When i use standartItemModel as the source of QIdentityProxyModel , i get QVariant(Invalid) values from the above data() function (in qDebug output...) . I was suspicious about the way i created the StandardItemModel. But it works well without the QIdentityProxyModel .
Here is how i implement the StandardItemModel,
adding a row to the model:
void TagChannelItemModel::addToTagModel(pEtiketDef_t tg)
{
int row = tagModel->rowCount();
QStandardItem* item = new QStandardItem(QString::number(tg.Id));
tagModel->setItem(row, TgIndex_Id, item);
item = new QStandardItem(tg.Name);
tagModel->setItem(row, TgIndex_Name, item);
item = new QStandardItem(QString::number(tg.PollFrequency));
tagModel->setItem(row, TgIndex_PollFreq, item);
}
Should i do anything else for this item model to work with ProxyModel ?
Thanks in advance...