I have a lot of models in my application. Some are normal QSqlTableModel's, some are sub-classed QSqlTableModel's, and other are sub-classed from QAbstractTableModel's.

What's the best/favorite/nicest way to keep track of columns in a model?

Here are some options that I thought of:

1. Hard-coding the column number:
Qt Code:
  1. model->setData(model->index(row, 4), value); //4 is the Name column
To copy to clipboard, switch view to plain text mode 

2. Using enums:
Qt Code:
  1. class MyModel : public QSqlTableModel {
  2. Q_OBJECT
  3. public:
  4. enum Columns {
  5. ColumnFirstName = 0,
  6. ColumnLastName,
  7. ColumnAddress,
  8. ColumnCount
  9. };
  10. //I use the last item, ColumnCount, to return in the columnCount(...) method
  11.  
  12. //class methods...
  13. };
To copy to clipboard, switch view to plain text mode 
and then:
Qt Code:
  1. model->setData(model->index(row, MyModel::ColumnFirstName), value);
To copy to clipboard, switch view to plain text mode 

3. Using some methods to pass QString's as column names (more useful in QSqlTableModel's I'd think)
Qt Code:
  1. int nameColumn = model->getColumn("name");
  2. model->setData(model->index(row, nameColumn), value);
To copy to clipboard, switch view to plain text mode 

I'm open to any more ideas you might have. I'm trying to find a balance between not depending too much on the database (how do we know which order the columns are when using a QSqlTableModel?) and ease of use.

Thanks