Hello all,
I want to do a QTableView with a custom calculate cell. In the first column I have the name of the device. In the second column I have millisecond field and in the third column I have the rest of the previous millisecond field row and the actual row and write in the second column. Also a have a filter to select the device.
I have a QStandardItemModel for update the data, and a QSortFilterProxyModel for the filter.
My code is:
this->model->setColumnCount(3);
this
->model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Time"));
this
->model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Milliseconds"));
this
->model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Spend Time"));
this->dataTable->setSortingEnabled(false);
this->dataTable->sortByColumn(1, Qt::AscendingOrder);
this->filterModel->setFilterRegExp(filterString);
this->filterModel->setFilterKeyColumn(-1);
this->dataTable->setModel(filterModel);
this->model = new QStandardItemModel();
this->model->setColumnCount(3);
this->model->setHeaderData(0, Qt::Horizontal, QObject::tr("Time"));
this->model->setHeaderData(1, Qt::Horizontal, QObject::tr("Milliseconds"));
this->model->setHeaderData(2, Qt::Horizontal, QObject::tr("Spend Time"));
this->dataTable = new QTableView();
this->dataTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
this->dataTable->setSortingEnabled(false);
this->dataTable->sortByColumn(1, Qt::AscendingOrder);
QRegExp filterString = QRegExp("ARM1", Qt::CaseInsensitive);
this->filterModel->setFilterRegExp(filterString);
this->filterModel->setFilterKeyColumn(-1);
this->dataTable->setModel(filterModel);
To copy to clipboard, switch view to plain text mode
When I don't use the filter, I can write in the data model without problem like this:
int rows = auxModel->rowCount();
for (int i = 0; i < rows; i++) {
if (i == 0) {
} else {
unsigned long aux1 = auxModel->data(auxModel->index(i,1)).toString().toLong();
unsigned long aux2 = auxModel->data(auxModel->index(i-1,1)).toString().toLong();
}
}
QStandardItemModel *auxModel = (QStandardItemModel*)this->dataTable->model();
int rows = auxModel->rowCount();
for (int i = 0; i < rows; i++) {
if (i == 0) {
auxModel->setItem(i, 2, new QStandardItem("0"));
} else {
unsigned long aux1 = auxModel->data(auxModel->index(i,1)).toString().toLong();
unsigned long aux2 = auxModel->data(auxModel->index(i-1,1)).toString().toLong();
QString s = QString::number(aux1 - aux2);
auxModel->setItem(i, 2, new QStandardItem(s));
}
}
To copy to clipboard, switch view to plain text mode
But when I use the filter I get a segmentation fault and I cannot found a solution.
Can anyone hellp me?
Thanks
Bookmarks