How can I get the info I need better than I do it right now?
-
Hi, I'm loading some info from an xml (which works fine, loading the info and showing it up is not the problem) but I work with that info in a really odd way so I wonder if there is any other better way.
Actually I have an XML which has a pair of values, something like:
ID="1" Name="Ana" ID="3" Name="Marta" (notice there is no ID=2) ID="4" Name="Pedro"
I have to show the names to the user so I use a combobox for it, and when the user selects a name I need to know the ID so..what I am doing now is using 2 combobox. The first one is going to be visible to the user with the names while the second one will be invisible and contain the IDs (one ID on each item). With that, if the user selects Marta for example, I know that Marta is the index 1 of the visible combobox.... then I select the index1 of the hidden combobox wich has the number 3 and I got the ID.
As I said its a really odd and ugly way so... is there any better way to do what I try?
I know I could just re-read the xml until the line N where N is the index of the combobox but I wanted to avoid having to re-read the xml (as its a file in the product of the enterprise and can cause some problems.
Thank you so much!
-
hi
Each item in the combobox can have a variant data
http://doc.qt.io/qt-5/qcombobox.html#addItemSo when you select one item, you can get the ID that way.
http://doc.qt.io/qt-5/qcombobox.html#currentData-prop
its a variant so it can be any data, but if you use a int, it has a fucntion to convert to int -
@roseicollis
Good to hear. :)
Most Widgets where you can insert "Item"
have this data property.