Hi,
This is my first post, because although you learn a lot from visits this forum, still have not found answer to this problem (apparently simple).
I have a QSqlRelationalTableModel and want to access the index value of the relationship without making a search related model.
For example:

Tables
Qt Code:
  1. mysql> describe user;
  2. +--------------+-------------+------+-----+---------+-------+
  3. | Field | Type | Null | Key | Default | Extra |
  4. +--------------+-------------+------+-----+---------+-------+
  5. | IdCategory | int(5) | NO | MUL | NULL | |
  6. | UserName | varchar(40) | NO | PRI | NULL | |
  7. | IdPerson | int(11) | YES | | NULL | |
  8. +--------------+-------------+------+-----+---------+-------+
  9.  
  10. mysql> describe category;
  11. +--------------+-------------+------+-----+---------+----------------+
  12. | Field | Type | Null | Key | Default | Extra |
  13. +--------------+-------------+------+-----+---------+----------------+
  14. | IdCategory | int(5) | NO | PRI | NULL | auto_increment |
  15. | NameCategory | varchar(80) | NO | UNI | NULL | |
  16. +--------------+-------------+------+-----+---------+----------------+
To copy to clipboard, switch view to plain text mode 

Code
Qt Code:
  1. QSqlDatabase Connection;
  2.  
  3. Connection = QSqlDatabase::addDatabase("QMYSQL");
  4. Connection.setHostName("192.168.0.21");
  5. Connection.setDatabaseName("brb");
  6. Connection.setUserName("user");
  7. Connection.setPassword("password");
  8.  
  9. Connection.open();
  10.  
  11. // table user
  12. modelUser = new QSqlRelationalTableModel;
  13. modelUser->setTable("user");
  14. modelUser->sort(modelUser->fieldIndex("UserName"), Qt::AscendingOrder);
  15. modelUser->setRelation(modelUser->fieldIndex("IdCategory"), QSqlRelation("category", "IdCategory", "NameCategory"));
  16. modelUser->select();
  17.  
  18. // table category
  19. QSqlTableModel* Category;
  20. Category = new QSqlTableModel;
  21. Category->setTable("category");
  22. Category->select();
  23.  
  24. int i, j;
  25. for(i = 0; i < 3;
  26. for(j = 0; j < modelUser->record().count(); j++)
  27. qDebug()<<modelUser->record(i).fieldName(j)<<" :"<<modelUser->record(i).value(j).toString();
  28.  
  29. qDebug()<<modelUser->record(0).value("IdCategory").toString();
  30. qDebug()<<modelUser->record(1).value("IdCategory").toString();
  31. qDebug()<<modelUser->record(2).value("IdCategory").toString();
To copy to clipboard, switch view to plain text mode 

Application output:
Qt Code:
  1. Starting C:\Qt\2010.04\projects\teste-build-desktop\debug\teste.exe...
  2.  
  3. "NameCategory" : "ADMINISTRATOR"
  4. "UserName" : "beatriz"
  5. "IdPerson" : "0"
  6.  
  7. "NameCategory" : "MANAGER"
  8. "UserName" : "ana"
  9. "IdPerson" : "0"
  10.  
  11. "NameCategory" : "SUPERVISOR"
  12. "UserName" : "bob"
  13. "IdPerson" : "0"
  14.  
  15.  
  16. ""
  17. ""
  18. ""
To copy to clipboard, switch view to plain text mode 

My question is whether it is possible to access the field value user.IdCategory without having to create a search algorithm in the model?
Can someone give me a direction?
The solution to this doubt, not only serves me in this simple example, but it helps me a broader understanding on the very QSqlRelationalTableModel.
My previous experience was with CBuilder / Zeoslib / MySql.
Thank you in advance and excuse my English.