开发者

Qt: QAbstractItemModel and 'const'

开发者 https://www.devze.com 2022-12-30 06:57 出处:网络
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 chan

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消