PDA

View Full Version : QComboBox QSqlQueryModel & relation.



matheww
19th June 2007, 00:32
Hi..

I have a form to show/edit data from a query, currently I am just showing data, this is not in a table so its line edits e.t.c.

I use a QSqlQueryModel with QDataWidgetMapper to get the data to display which is fine for plain data from the table, but as a good db guy, i use relations as well..

So, I have a QComboBox who's list items are filled by a QSqlQueryModel that gives two rows, a primary key and display text.. what I want to do is link the primary key to a value in my first query model to show the correct display text.. Any ideas?

I dont mind sub-classing the QComboBox, but would like to avoid it if I can..

:)
Qt 4.3.0, Fedora Core 7 x86_64, QDevelop

wysota
19th June 2007, 09:55
This should help:

dataWidgetMapper->setItemDelegate(new QSqlRelationalDelegate(dataWidgetMapper));

matheww
20th June 2007, 05:56
I will look into it, at the moment I have hard-coded lookups into the combo, I might have to sub-class a combobox to handle key values, then it might work as I would like..

:)