Results 1 to 4 of 4

Thread: Questions regarding setting up a Qt SQL Model/View

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Questions regarding setting up a Qt SQL Model/View

    This is not the exact database I am working with, but a simplified version of it showing my main problem. So, let's assume we have the following SQL Database structure:
    Qt Code:
    1. Table A - a list of employees:
    2. id - primary key
    3. name - string describing a persons name
    4.  
    5. Table B - a list of offices:
    6. id - primary key
    7. location - string describing an office location of a person from table a
    8.  
    9. Table C - a list of company cars:
    10. id - primary key
    11. car - string describing the type of car of a person from table a
    12.  
    13. Table A_B_Relation - each person can belong to multiple offices:
    14. a_id - foreign key to table A.id
    15. b_id - foreign key to table B.id
    16.  
    17. Table A_C_Relation - each person can own several company cars:
    18. a_id - foreign key to table A.id
    19. c_id - foreign key to table C.id
    To copy to clipboard, switch view to plain text mode 

    The displayed overview of people and cars they own/offices they belong to should look like the attached image.

    The main problem that bugs me is: How to set up the QSqlRelationalTableModel properly?
    When I set it up using table A as main table then I fail to find a way of displaying the car / office names - QSqlRelation only allows me to display the IDs of each role, or did I miss something in the docs about using it for this kind of thing? Currently I think that I will have to write my own model - am I correct there? It is certainly possible to simply use a QSqlTableModel and set a custom sql query on it which would deliver the data in a way that I could display it as I want using standard Qt classes.
    But then there comes the problem with editing the displayed data in a proper way. I assume that safely editing the fields would require a custom delegate, no?

    I am a bit puzzled if I am trying the correct approach on this issue.
    Attached Images Attached Images
    "If you lie to the compiler, it will get its revenge." - Henry Spencer

Similar Threads

  1. Model/View -- Sql Insert
    By kroenecker in forum Qt Programming
    Replies: 3
    Last Post: 3rd May 2007, 15:55
  2. Sql questions
    By Nb2Qt in forum Qt Programming
    Replies: 4
    Last Post: 15th February 2007, 22:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.