C++ Qt C++;-在一个视图中显示多个SQLite表中的数据
Qt版本:5.8 假设我有以下SQL表C++ Qt C++;-在一个视图中显示多个SQLite表中的数据,c++,qt,sqlite,qtsql,C++,Qt,Sqlite,Qtsql,Qt版本:5.8 假设我有以下SQL表 -- People person_id | first_name | last_name | age -- Cars, person_id is a foreign key to show that this person owns this car car_id | car_year | car_make | car_model | person_id 假设我想用这样的混合数据填充下面的表视图或表小部件 // Table that the user
-- People
person_id | first_name | last_name | age
-- Cars, person_id is a foreign key to show that this person owns this car
car_id | car_year | car_make | car_model | person_id
假设我想用这样的混合数据填充下面的表视图或表小部件
// Table that the user sees. Notice that not all the information from the tables is shown.
first_name | last_name | car_year | car_make | car_model
最好的/推荐的方法是什么?我可以看到以下两种方法,但我觉得这两种方法都不是最好的方法
我觉得#1是这两者中的佼佼者,但我想知道是否还有比这两者更好的方法。如果
person\u id
是tablepeople
的主键,您可以使用QtSql.QsqlRelationalTableModel
在qtwidget.QTableView
中显示多个表中的数据,以下是您的示例:
QSqlRelationalTableModel rm = new QSqlRelationalTableModel(parentObject, database);
rm→setTable(„cars“);
rm→setRelation(4, QSqlRelation(„people“, „person_id“, „first_name, last_name“);
rm→select();
QTableView tv = new QTableView();
tv→setModel(rm);
tv→hideColumn(0); # hide column car_id
hh = tv->horizontalHeader();
hh→moveSection(4, 0); # change order of columns
hh→moveSection(5, 1);
可能重复的