I have some list and QInputDialog. There may be same strings in my list, so i want to get not the string result but item index. Is it real?
QStringList list;
for (Serial serial: serialList->vector) {
list.append(serial.name);
}
QInputDialog *dialog = new QInputDialog();
bool accepted;
QString item = dialog->getItem(0, "Title", "Label:", list, 0, false, &accepted);
if (accepted && !item.isEmpty()) {
qDebug() << dialog->?????; //here i want to see index of choosen item
}
I've tried to use result() but it is not working. Help, please.
No, QInputDialog has no such method. But of course this information has combobox inside dialog.
I think that it is not good idea. Look at the source code of QInputDialog:
void QInputDialog::setComboBoxItems(const QStringList &items)
{
Q_D(QInputDialog);
d->ensureComboBox();
d->comboBox->blockSignals(true);
d->comboBox->clear();
d->comboBox->addItems(items);
d->comboBox->blockSignals(false);
if (inputMode() == TextInput)
d->chooseRightTextInputWidget();
}
As you can see your combobox is hidden by d-pointer and it is normal practice in Qt(hide implementation details). More information here.
Use indexOf() method from QStringList. For example:
int index = list.indexOf(item);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With