refresh comboBox with new value
-
Hello, i try to refresh my comboBox with another value and it don't work.!
. Can you help me?
-
void info_client::actualiser_combox(QString val)
{
nNumVal = val;if(!nNumVal.isEmpty()) { ui->num->setCurrentText(nNumVal); qDebug()<<"VALEUR RECUPERRER "+nNumVal+" "+ui->num->currentText(); }
}
I check if variable nNumVa is not empty before... to want to refresh.
-
void info_client::actualiser_combox(QString val)
{
nNumVal = val;if(!nNumVal.isEmpty()) { ui->num->setCurrentText(nNumVal); qDebug()<<"VALEUR RECUPERRER "+nNumVal+" "+ui->num->currentText(); }
}
I check if variable nNumVa is not empty before... to want to refresh.
-
Ok, sorry, indeed I get a value from an old interface so I want to display this value in my comboBox , the function I wrote allowing to update my comboBox with the value received is the one whose code is currently sent. But it happens that the value is not showing in the comBobox although I retrieve it correctly in my console with the qDebug below that you see... Thanks
-
Ok, sorry, indeed I get a value from an old interface so I want to display this value in my comboBox , the function I wrote allowing to update my comboBox with the value received is the one whose code is currently sent. But it happens that the value is not showing in the comBobox although I retrieve it correctly in my console with the qDebug below that you see... Thanks
@Alfredy Is your combo box set as editable?
Please read https://doc.qt.io/qt-6/qcombobox.html#currentText-prop
"If the combo box is editable, the current text is the value displayed by the line edit. Otherwise, it is the value of the current item or an empty string if the combo box is empty or no current item is set." -
Thanks @jsulm for you help, Yes my comboBox was editable but I change this, and I try to use setEditable for modify my comboBox value but it is same problem.
@Alfredy Sorry, I don't understand: what did you change? You made your combo box not-editable? In that case setCurrentText will try to find a text in the combo box like the one you're trying to set and then sets the current index if found. If not found nothing will happen. It is explained in the documentation, please read it:
"The setter setCurrentText() simply calls setEditText() if the combo box is editable. Otherwise, if there is a matching text in the list, currentIndex is set to the corresponding index." -
@Alfredy
If you made the combo not-editable it will not work.Why don't you replace your whole body code (get rid of the
if
) with:qDebug() << "Setting value"; ui->num->setCurrentText("1234"); qDebug()<<"Set value " + ui->num->currentText();
and see what happens?