Results 1 to 9 of 9

Thread: QSqlRelationalTableModel: get non-resolved value of item

  1. #1
    Join Date
    Aug 2006
    Location
    Russia, St. Petersburg <-> Omsk
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlRelationalTableModel: get non-resolved value of item

    QSqlRelationalTableModel::data( const QModelIndex & index, int role = Qt::DisplayRole ) returns display values for items from relation columns, but is there a way to get the index value for them, as it was in the original table before resolving?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel: get non-resolved value of item

    Did you try Qt::EditRole? It probably returns the foreign key and not the related value.

  3. #3
    Join Date
    Aug 2006
    Location
    Russia, St. Petersburg <-> Omsk
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRelationalTableModel: get non-resolved value of item

    Yes, it would be natural if Qt::EditRole did so, but unfortunatly it doesn't (it would be cool to have something like Qt::ForeignKeyRole for QSqlRelationalTableModel).
    The only way i found is to create view with duplicated column in my database and resolve one of two

  4. #4
    Join Date
    Aug 2006
    Location
    Russia, St. Petersburg <-> Omsk
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRelationalTableModel: get non-resolved value of item

    QSqlRelationalTableModel doesn't work with MySQL views at all...
    So, I need two models for this table: one with relations set and other without..

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel: get non-resolved value of item

    Naaa... it's not that bad. You can always use QSqlQueryModel::record() which will return the real record, with the foreign key instead of resolved relation.

  6. #6
    Join Date
    Aug 2006
    Location
    Russia, St. Petersburg <-> Omsk
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRelationalTableModel: get non-resolved value of item

    QSqlRelationalTableModel overrides completely all foreign keys with their values and i get record with values already resolved... Qt coding is not so fun in this place...

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel: get non-resolved value of item

    Quote Originally Posted by ak View Post
    QSqlRelationalTableModel overrides completely all foreign keys with their values and i get record with values already resolved...
    So use the relation model and check the index yourself. What do you need it for anyway? What's the point in hiding foreign keys if you want to access them later on?

    Qt coding is not so fun in this place...
    Hmm... You ask Qt for a car and you are complaining it gave you a car instead of a bicycle?

  8. #8
    Join Date
    Aug 2006
    Location
    Russia, St. Petersburg <-> Omsk
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRelationalTableModel: get non-resolved value of item

    What do you need it for anyway? What's the point in hiding foreign keys if you want to access them later on?
    Hmm... You ask Qt for a car and you are complaining it gave you a car instead of a bicycle?
    QSqlRelationalTableModel is very helpful when i want to show one table, but if i want to fill the dialog with additional info about some of fereign keys (e. g. mesure unit and producer of requested product from one of requests), i need non-resolved index, other words, i need functionality of both car and bicycle.
    Or don't i just know what i realy need?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel: get non-resolved value of item

    I don't understand what you mean by "additional info about some of foreign keys". A key is a key (number), nothing more. If you want more information retrieved from the other table either use a view (in terms of the database, not model-view), use QSqlQueryModel, use a proxy model or use the base implementation of data - explicitely call QSqlTableModel::data instead of QSqlRelationalTableModel::data.

Similar Threads

  1. Replies: 3
    Last Post: 4th April 2008, 19:51
  2. combobox and item colors
    By zorro68 in forum Qt Programming
    Replies: 16
    Last Post: 23rd September 2007, 12:54
  3. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 07:09
  4. Replies: 1
    Last Post: 19th April 2007, 22:23
  5. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34

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.