PDA

View Full Version : problem with comboBox



tinysoft
2nd May 2010, 14:17
hi every body

i am facing problem with the combo Box ... i want to change its current value on text edite at line Edit ... so i used this slot :


void CheckoutDialog::on_empNoEdit_textChanged(QString number)
{

int i=query.record().indexOf(number);


ui->empNameBox->setCurrentIndex(i);

}


at execute the combo box do nothing :(

could any one tel me what i am missing ?

great thanx

Lykurg
2nd May 2010, 14:39
Ehm, what is what??? make sure i is set to the right value, and is query valid in your slot? and is it called after all?

tinysoft
3rd May 2010, 07:18
i changed the code theory to this one and its worked fine :) :



void CheckoutDialog::on_empNoEdit_textChanged()
{

int k=1;

query.first();

//_______check for item(0)____________
if (ui->empNoLine->text().toInt()==query.value(0).toInt())

{
ui->empNameBox->setCurrentIndex(k);


}
//_____________________________________


//_______for the rest of items___________

while(query.next())

{


if (ui->empNoLine->text().toInt()==query.value(0).toInt())

{
ui->empNameBox->setCurrentIndex(k);

break;
}


k++;
}
//_________________________________________

}


is there any way to do this in a simple way ?

Lykurg
3rd May 2010, 07:29
is there any way to do this in a simple way ?
Yes, surely! But You still haven't said what the content of query is, what in your combo box is displayed etc...

One (of some) improvements: use a do-while scope. (or for loop) So you can integrate the check of the first item

tinysoft
3rd May 2010, 07:42
the query is containing numbers of employees , the combo box containing there names, so i sorted the query by the names alphabet like this :


query.exec("select emp_no from employees order by name;");

i want to synchronize the line Edit with the combo box so when user enter number to the line edit , i should get the index of that number on the query and send the index to the combo box to be its current index number.

Lykurg
3rd May 2010, 08:01
Instead of alway query the database set the id direct as user data to your combo box. then simply loop through the box and check there. Or if it is a long combo box create a local index hash.