Displaying RelationalModel in tableview
Hi Everyone,
What I am doing is, I am creating 2 tables,
Quote:
userFp(Primary table), user(Foreign key table)
. Then I am trying to display the resulting RELATION in a tableview. But I am not able to detect what's going wrong with my code. Following is my code:
Code:
QSqlQuery query
(db
);
//db is the QSqlDatabase created on QSqlite ret = query.exec("PRAGMA foreign_keys = ON;");
ret = query.exec("create table userFp(FpID INTEGER PRIMARY KEY, FpCount INTEGER)");
ret=query.exec("create table user(UserID INTEGER PRIMARY KEY,Name varchar(50),"
"FpID INTEGER, FOREIGN KEY(FpID) REFERENCES userFp(FpID) ON UPDATE CASCADE)");
.....
.....
..... inserting the values into the 2 tables
.....
.....
model->setTable("user");
model
->setRelation
(2,
QSqlRelation("userFp",
"FpID",
"FpCount"));
//NOTE- Here I am not sure whether to give column index as 3 or 2. I tried with both.
ui->tableView->setModel(model);
The Problem is I am not getting any error upon execution, but my ui->tableview remains blank. Can anyone point out where I am going wrong or rather what I am missing? :confused:
With regards,
sattu