better way to set data in a QCombobox
Hello,
I'm implementing my "QCombobox set current data" and I’m in doubt about what is the better way?
1) using variable and QMapIterarot to manipulate data, and QCombobox.setCurrentText()
Code:
QMapIterator<QString, int> i(_cbNames);
while (i.hasNext()) {
i.next();
if (query2.value(1) == i.key())
{
ui->qcomboboxNames->setCurrentText(i.key());
}
2) using directly combobox to manipulate data and QCombobox.setCurrentIndex()
Code:
for (int i=0;i<=ui->qcomboboxNames->count();i++)
{
ui->qcomboboxNames->setCurrentIndex(i);
if (query2.value(1) == ui->qcomboboxNames->currentText())
{
break;
}
}
Thanks!
Juliano
Re: better way to set data in a QCombobox
Re: better way to set data in a QCombobox
Quote:
Originally Posted by
jefftee
Hello, thanks for your reply, but I dont have doubts about add item. My doubt is What of 2 methods (or another) are the Best way to set the current data in a combobox witch Already have items.
Thanks
Juliano
Re: better way to set data in a QCombobox
If that's all you're asking, surely you can time both methods and decide for yourself which is better, right?
Re: better way to set data in a QCombobox
Why not like this :
Code:
int index = ui->qcomboboxNames->findText(query2.value(1));
if( index >= 0 )
ui->qcomboboxNames->setCurrentIndex(index);
Re: better way to set data in a QCombobox
Quote:
Originally Posted by
Lesiok
Why not like this :
Code:
int index = ui->qcomboboxNames->findText(query2.value(1));
if( index >= 0 )
ui->qcomboboxNames->setCurrentIndex(index);
Yeah! This code is more simple and clear, thanks bro!