【发布时间】:2013-10-21 10:31:51
【问题描述】:
我正在尝试从QCombobox使用finddata(索引)中获取模型中记录的ID,但在选择一个项目时,它将重新调整-1。它一直在另一个项目中工作,但这是第二个不起作用的项目。这是我的代码:
modAnfi = new QSqlTableModel(this);
modAnfi->setQuery("SELECT id, (nombres || ' ' || apellidos) as Nombre, nombres, apellidos FROM tbPersonas WHERE activo=1");
comboAnfitrion->setModel(modAnfi);
comboAnfitrion->setModelColumn(1);
comboAnfitrion->setEditable(true);
comboAnfitrion->completer()->setCompletionMode(QCompleter::PopupCompletion);
connect(comboAnfitrion, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChangeAnfitrion(int)));
和:
void controlReg::currentIndexChangeAnfitrion(int index)
{
qDebug() << comboAnfitrion->findData(index); // -1
qDebug()<< comboAnfitrion->itemData(1); // QVariant(Invalid)
}
感谢您的宝贵时间,我们将不胜感激。
【问题讨论】: