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:

Qt Code:
  1. QVariant TableViewQryModel::data(const QModelIndex &idx, int role) const
  2. {
  3. QVariant v = QSqlQueryModel::data(idx, role);
  4.  
  5. if (!idx.isValid())
  6. return QVariant( );
  7.  
  8. if (role == Qt::DisplayRole && idx.column() > 0 &&
  9. index(idx.row(), idx.column(), idx.parent()).data().toString() == "0")
  10. {
  11. return QVariant("-");
  12. }
  13. else if (role == Qt::TextAlignmentRole)
  14. {
  15. return int(Qt::AlignCenter | Qt::AlignVCenter);
  16. }
  17.  
  18. return (v);
  19. }
To copy to clipboard, switch view to plain text mode 

Thanks,

Marcelo E. Geyer