SetCurrent text of comboBox
Solved
General and Desktop
-
ui->Lista->addItem(Nome_Config_nuovo);
How can I do to set the new item as current Item?
-
well you can use setCurrentIndex(int index)
the last inserted have count() -1 as index -
@vale88
That is because you havesetCurrentIndex(-1)
. What do you expect it to set as the current item in such a circumstance, especially since https://doc.qt.io/qt-5/qcombobox.html#currentIndex-prop states:By default, for an empty combo box or a combo box in which no current item is set, this property has a value of -1.
Come on, think about it first, @mrjj wrote:
the last inserted have count() -1 as index
ui->Lista_Configurazione->setCurrentIndex(ui->Lista_Configurazione->count() - 1);
means the last item in the list (i.e. the one you have just added), doesn't it?