PDA

View Full Version : FOREIGN KEY + QComboBox



eleanor
7th November 2007, 14:03
Hi, I've created an application that's based on mysql table.

Mysql table has FOREIGN KEYs set from first tables's field (town) to second table's field (also town)


What I want to do now is to add a QComboBox (that points to the first table's field town, but when I click drop-down button I want to display the values that are stored in second table's field (town) and write that town to the first table's field.

The problem is that I want to automatically detect that mysql table's field have relations set (with FOREIGH KEY) so that dropdown menu can display itself properly.

Any ideas how to do that?

jpn
8th November 2007, 11:37
QSqlRelationalTableModel and QSqlRelationalDelegate can handle relations for you, but I'm afraid you will have to establish relations by hand. I have no idea whether it's possible with Qt to detect possible relations in any arbitrary table.