Using QComboBox with QSqlQueryModel
-
To speed-up
QComboBoxwork with very big data set want to try to useQSqlQueryModelinstead ofQStandardItemModel. However text data in QComboBox I need to map to an ID, which is stored and accessible currently byitemData(rowIndex, Qt::UserRole). InQSqlQueryModelquery there will be 2 columns: ID and Text; andQComboBox setModelColumn(1)is defined, i.e. Text.How to correctly subclass or redefine
QSqlQueryModel, ifcombobox->itemData(rowIndex, Qt::UserRole)have to contain ID? Who had implemented such things or know link to a source? If I defineQVariant QSqlQueryModel::data ( const QModelIndex & item, int role = Qt::DisplayRole )in a such way:QVariant MySqlModel::data(const QModelIndex &index, int role) const { if(role == Qt::UserRole && index.column() == 1) return QSqlQueryModel::data(this->index(index.row(), 0), Qt::DisplayRole); return QSqlQueryModel::data(index, role); }will it work, i.e. whether
combobox->itemData(rowIndex, Qt::UserRole)will contain ID in this case? Or need to investigate Qt sources? -
To speed-up
QComboBoxwork with very big data set want to try to useQSqlQueryModelinstead ofQStandardItemModel. However text data in QComboBox I need to map to an ID, which is stored and accessible currently byitemData(rowIndex, Qt::UserRole). InQSqlQueryModelquery there will be 2 columns: ID and Text; andQComboBox setModelColumn(1)is defined, i.e. Text.How to correctly subclass or redefine
QSqlQueryModel, ifcombobox->itemData(rowIndex, Qt::UserRole)have to contain ID? Who had implemented such things or know link to a source? If I defineQVariant QSqlQueryModel::data ( const QModelIndex & item, int role = Qt::DisplayRole )in a such way:QVariant MySqlModel::data(const QModelIndex &index, int role) const { if(role == Qt::UserRole && index.column() == 1) return QSqlQueryModel::data(this->index(index.row(), 0), Qt::DisplayRole); return QSqlQueryModel::data(index, role); }will it work, i.e. whether
combobox->itemData(rowIndex, Qt::UserRole)will contain ID in this case? Or need to investigate Qt sources?