Qt: QAbstractItemModel and 'const'
I'm trying to use a QTreeView for the first ti开发者_JS百科me with QAbstractItemModel and instantly have a problem. QAbstractItemModel interface declares methods as const
, assuming they will not change data. But I want the result of a SQL query displayed, and returning data for a record with specified index requires the use of QSqlQuery::seek() which is non-const. Are there any 'official' guidelines to using a QAbstractItemModel with data that must be changed in order to get the number of items, data per item etc? Or must I hack C++ with const casts?
You can get away without any const casts by holding a pointer to the QSqlQuery; your pointer won't change, only the value to which you point, hence the operation will still be considered "const".
精彩评论