QSqlRelationalTableModel and QSqlRelationalDelegate can handle relations for you, but I'm afraid you will have to establish relations by hand. I have no idea whether it's possible with Qt to detect possible relations in any arbitrary table.