PDA

View Full Version : QDataWidgetMapper <=> QComboBox best practice



saknopper
11th January 2007, 17:18
Hi all,

I'm writing an application with a database back-end and I'm really stuck using QDataWidgetMapper in combination with a QComboBox.

In my opinion the API documentation is a bit unclear about this and I couldn't find any examples.

Anyhow, I've got 2 tables. One table has a foreign key referring to the other table. For this field I'd like to use a QComboBox.

First of all, should I use a model with support for relations or do the id's of the foreign key suffice? Second, does QDataWidgetMapper take care of loading all available options (from the other table) into the QComboBox or should I do this? Last but not least, if I have to do this myself, what's the best way to deal with the id's of the database and the indices of the QComboBox?

wysota
18th January 2007, 10:50
First of all, should I use a model with support for relations or do the id's of the foreign key suffice?
Both approaches are fine.

Second, does QDataWidgetMapper take care of loading all available options (from the other table) into the QComboBox or should I do this?
If you use a relation, it is highly probable it will do it by itself. As for ids - I'm not sure, but probably it will too (although the usability of such solution is highly questionable).

Last but not least, if I have to do this myself, what's the best way to deal with the id's of the database and the indices of the QComboBox?

If you have to do it yourself, you can set a model for the combobox to fetch the options from. Then you'll only have to connect it to the widget mapper (or whatever other solution you want) to update the actual model if you choose another item in the combobox.