PDA

View Full Version : QComboBox and QSqlRelationalTableModel



diantre
30th May 2017, 12:00
Hello,

I'm trying to fill a QComboBox with my QSqlRelationalTableModel this way:

First I populate my model:
model->setTable();
model->select();
model->setRelation();

After that I set the model for my QComboBox:

comboBox->setModel(model);
comboBox->setModelColumn(2);

And I use a QDataWidgetMapper:

mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->setModel(model);
mapper->addMapping(comboBox,2);

Following this post:

http://www.qtcentre.org/threads/24350-QComboBox-Delegate-QDataWidgetMapper-QSqlRelationalTableModel

The point is, the comboBox is actually filled (I can print all its values on the prompt) but nothing appears in the QComboBox.
I'm assuming that it may be a format problem? Or it's about the Qt::DisplayRole but I didn't find a proper way to make it works.

Thanks for your help

wysota
1st June 2017, 23:26
You definitely need to set the relational delegate on the combobox. There is no need to use QDataWidgetMapper here.