You have to combine items together.
And then add only those combined items to the list.Qt Code:
To copy to clipboard, switch view to plain text mode
You have to combine items together.
And then add only those combined items to the list.Qt Code:
To copy to clipboard, switch view to plain text mode
Thanks, it works.
Now I only need to know how slow will this work. Because in the future I'll have to add 100.000 towns in the mysql table and in QComboBox. So will this be instant, or will take a lot of time.
And how to add items in that QComboBox based on alpabetical order?
Are you sure having a combobox with 100000 items is a good idea? How do you expect anyone to find anything there? Maybe it'd be better to provide a separate dialog with a list and search facilities to choose the town?
Sort the list before adding it to the combo box.And how to add items in that QComboBox based on alpabetical order?
Qt Code:
while(query.next()) { //value 0 corresponds to ime in SELECT statement town = query.value(0).toString(); town_number = query.value(1).toString(); combined = town + " " + town_number; comb.append(combined); } //sort the list of items in ascending order //comb.sort(); QMap<QString,QString> comb; kraj_combo->insertItems(0,comb);To copy to clipboard, switch view to plain text mode
- I want to sort items apphabetically but not case sensitively. I'm not sure how to do it?
Well, if you type in the QCobmoBox a name or a number (I added in the previous post) then it throws you on that name, you don't have to search through that manually. I'm just worried that it would be too slow, would it?
Town names usually start with capital letters, so what's the problem with case sensitivity? Anyway you can provide your own lessThan implementation that will do a case insensitive comparison.
Ok, but it looks pretty bad.Well, if you type in the QCobmoBox a name or a number (I added in the previous post) then it throws you on that name, you don't have to search through that manually.
Adding and first display might be slow. Later it should work instantly.I'm just worried that it would be too slow, would it?
Now I created 2 QComboBOxes like this:
Qt Code:
QStringList comb,comb_number; QString town, town_number;//, combined; while(query.next()) { //value 0 corresponds to ime in SELECT statement town = query.value(0).toString(); town_number = query.value(1).toString(); //combined = town + " " + town_number; comb.append(town); comb_number.append(town_number); } //sort the list of items in ascending order (case-sensitively) comb.sort(); comb_number.sort(); //QMap<QString,QString> comb; kraj_combo->insertItems(0,comb); kraj_combo_number->insertItems(0,comb_number);To copy to clipboard, switch view to plain text mode
but, I what I want to do is this: when one of the items is selected (in either of the QComboBoxes) I want to adjust the second one to the same value (based on the ID number) in the table.
So for example there is an entry like this in table:
London 1000
when I choose 1000, I want the other QComboBox to set itself to London and the other way around. Any idea how to do that?
Take a look at signals and slots QComboBox offers.
Yes, I did...it would be easy this way:
Qt Code:
connect(kraj_combo,SIGNAL(currentIndexChanged(int)),kraj_combo_number,SLOT(setCurrentIndex(int)));To copy to clipboard, switch view to plain text mode
but the problem with this code is that I sort the QComboBox and the indexes do not match. I want to match them based on ID in mysql table.
Any idea?
So provide a two way mapping between the id and the name. Then you can see which index in one combobox corresponds to the same item in the other and select the appropriate item.
Two wa mapping.WHat's this?
Can you express this with an example please?
Two way mapping - mapping from name to id and from id to name. So that you know that if London has index 7 in one list, it has index 12 in the other list and that if it has index 12 in the second list, it has index 7 in the first one.
Bookmarks