QComboBox Foreign Key
Solved
General and Desktop
-
Good day!
In my application I work with SQLite3 database where 3 tables are stored. One of these table has a foreign key constraints and refers to other 2 tables:CREATE TABLE munits ( id INTEGER PRIMARY KEY NOT NULL, munit TEXT NOT NULL UNIQUE ) CREATE TABLE ctypes ( id INTEGER PRIMARY KEY NOT NULL, ctype TEXT NOT NULL UNIQUE ) CREATE TABLE sa_kinds ( id INTEGER PRIMARY KEY NOT NULL, sa_kind TEXT NOT NULL UNIQUE, munit_id INTEGER NOT NULL, ctype_id INTEGER NOT NULL FOREIGN KEY(munit_id) REFERENCES munit(id), FOREIGN KEY(ctype_id) REFERENCES ctype(id) )
Tables
ctypes
andmunits
are linked withQSqlTableModel
,sa_kinds
- withQRelationalTableModel
.
Each table is binded with a separateQTableView
, but I edit data not in the cells directly - I wrote a separate modal dialog with QLineEdits and QComboBoxes.What I want to achieve:
- Human-readable values in the parent
sa_kinds
table instead ofid
codes when it is displayed in QTableView - When I edit
sa_kinds
table's data in the modal dialog, I want QComboBoxes to show human-readable values frommunits
andctypes
tables in a drop-down lists but, after clickingOK
, to update row with correspondingid
codes
Thanks in advance.
- Human-readable values in the parent
-
Hi,
You can set your table model on the combo box so you can choose the text you want and based on that you can retrieve the id you are looking for.