Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[solved] Combobox UserRole ?
How can i get the enum values of Parity ?
I expect to get 0, 2 and 3
Problem is, i do not understand the USerrole stuff.
@ ui->cb_test->addItem("NO", QSerialPort::NoParity);
@void MainWindow::on_cb_test_currentIndexChanged(int index)
qDebug() << index;
qDebug() << ui->cb_test->itemData(index, 0);
@qDebug() << ui->cb_test->itemData(index, 0);@
You are using the wrong role here. By default itemData gets the data from Qt::UserRole so what you put in using addItem. Here you are requesting the data from Qt::DisplayRole
do you have a suggestion how i can solve my problem ?
@qDebug() << ui->cb_test->itemData(index);@
the output of the above is:
QVariant(int, 3) @
I want to use this combobox to set QSerialPort parity:
And that's the correct output.
If you want to retrieve the value you have to convert the QVariant back to your enum
Ahhhhh :), OK thank you
Since you have everything working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)