Hello to everybody,
To solve this problem, i trying to subclass a QSqlRelationalDelegate, so that, at che column of second combobox, I can apply a filter on the QSqlTableModel returned by relationalModel; but i can't do this, because the delegate use only a const QModelIndex so i can't access the complete model and use the setFilter method. This is my code:
{
switch(index.column()) {
case 4:{
sqlModel
->setFilter
(QString("CodProvincia=%1").
arg(sqlModel
->index
(index.
row,
10).
data().
toInt());
QComboBox * combo
= qobject_cast<QComboBox
*>
(editor
);
if (!sqlModel || !combo){
return;
}
combo->setCurrentIndex(combo->findText(sqlModel->data(index).toString()));
break;}
void setEditorData(QWidget *editor, const QModelIndex &index) const
{
switch(index.column()) {
case 4:{
const QSqlRelationalTableModel * sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
sqlModel->setFilter(QString("CodProvincia=%1").arg(sqlModel->index(index.row,10).data().toInt());
QComboBox * combo = qobject_cast<QComboBox *> (editor);
if (!sqlModel || !combo){
QItemDelegate::setEditorData(editor,index);
return;
}
combo->setCurrentIndex(combo->findText(sqlModel->data(index).toString()));
break;}
To copy to clipboard, switch view to plain text mode
But it return an error, because the index is only a constant. This is the error:
..\picloaddelegate.h:24: error: passing 'const QSqlRelationalTableModel' as 'this' argument of 'virtual void QSqlTableModel::setFilter(const QString&)' discards qualifiers
Any ideas of how resolve it?
thanks a lot for your time!
Michele
Bookmarks