Error format a cell in QTableView
Hi guys,
I have a QTableView with four columns. I reimplement the virtual method data( ) to align text the cells. So far, so good, but I also want to replace the cells where the value is 0 (zero) for a dash ("-"). While trying to do this, my application compiles correctly but gives an error of segmentation fault when I open the window.
See the code:
Code:
{
if (!idx.isValid())
if (role == Qt::DisplayRole && idx.column() > 0 &&
index(idx.row(), idx.column(), idx.parent()).data().toString() == "0")
{
}
else if (role == Qt::TextAlignmentRole)
{
return int(Qt::AlignCenter | Qt::AlignVCenter);
}
return (v);
}
Thanks,
Marcelo E. Geyer
Re: Error format a cell in QTableView
Quote:
Originally Posted by
estanisgeyer
if (role == Qt::DisplayRole && idx.column() > 0 &&
index(idx.row(), idx.column(), idx.parent()).data().toString() == "0")
This causes an infinite recursion.
Use:
Code:
if( role
== Qt
::DisplayRole && idx.
column() >
0 && QSqlQueryModel::data( idx
).
toString() == "0" ) { ...
or, since you call data() in the first line:
Code:
if( role == Qt::DisplayRole && idx.column() > 0 && v.toString() == "0" ) {
...
Re: Error format a cell in QTableView
Ok, it's works!
I do not understand where this happens recursion, could you explain?
Thanks,
Marcelo E. Geyer
Re: Error format a cell in QTableView
Hi,
you call index() with the row, column and parent of the index you are testing, ergo get the same index, and then call data() (the method you are already in), which will calls index() with the row, column and parent of the index you are testing, ... until infinity.
Ginsengelf