PDA

View Full Version : QtSqlRelationalTableModel question



scott_hollen
25th February 2011, 17:04
Yet another design question - moving on from my earlier one (still in design phase).

I have unique data in one DB table. It is linked via a foreign key reference to a child table. Ideally I'd like to create a combobox which is populated by the values in my parent table. Upon selection (or creation of a new parent item), another combo box would be populated with the unique names of the children. Upon selection of a child, a QTableView would then be populated with the attributes of that particular child.

For example:

{Musician} -> This is the unique parent

{Album} -> linked to the parent via foreign key; may not be unique based on current DB design

By SELECTing an album, the QTableView would be populated with the album tracks.

So my question is: I'd like to use q QSqlRelationalTableModel to handle editing of this data via widget mapping, but I'm wondering if that is a viable approach. My initial thoughts were that I'd have to manage this with 2 different models and keep it all in sync behind the scenes, especially when editing but obviously I don't know which in the end would be the easiest -- and cleanest -- approach (which I'm thinking about limiting to adding or copying due to other down-the-road issues).

I should experiment with both to see but my time is very limited and I'm trying to avoid my father-in-law's theory of "code twice, throw away once" and nail down a solid design before I actually start coding...

Added after 59 minutes:

Actually, I think I just answered my own question as I found a very, very similar example in the C++ GUI Programming with Qt4, Second Edition book...