Results 1 to 6 of 6

Thread: Get Value of Foreign Key in QSqlRelationalTableModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Get Value of Foreign Key in QSqlRelationalTableModel

    I'm using a QSqlRelationalTableModel. It's handy, since field values from tables referenced by the foreign keys are displayed automatically.

    But, I need to use the foreign key to get data from other tables to set up an editor widget. I don't see a method for that in QSqlRelationalTableModel.

    Am I missing it?

    Thanks,

  2. #2
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Get Value of Foreign Key in QSqlRelationalTableModel

    QSqlRelationalDelegate has createEditor method, if that is what you are asking

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Get Value of Foreign Key in QSqlRelationalTableModel

    If I understand the question correctly, you want the actual value in the joined column, not the display value obtained from the related table. There does not seem to be a direct way to obtain this. Bot the DisplayRole and EditRole return the mapped value. The QSqlRelationalDelegate actually looks up the display text in the relationModel() to find the id for its combo box drop down (this works only for simple lookup tables though). You could retrieve the primary key of the main table from the model and use that in a joined query when looking up the other tables.

Similar Threads

  1. Replies: 6
    Last Post: 12th October 2015, 08:59
  2. How to deal with foreign key in Qt
    By sjyzhxw in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2012, 09:31
  3. Replies: 0
    Last Post: 2nd April 2011, 16:50
  4. Replies: 1
    Last Post: 2nd April 2011, 16:40
  5. Foreign key ON
    By fantom in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 10:32

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.