The QSqlQueryModel will only fetch data in an unstructured form. So, when you:
treeView->setModel(sqlQueryModel);
treeView->setModel(sqlQueryModel);
To copy to clipboard, switch view to plain text mode
You have all the values of the query displayed in an unstructured form.
There are a couple of suggestions on the web, and the easiest one seems to be to create a QStandardItemModel and create a hierarchy from the SQL query. I have a method at the moment (note: it won't compile and there are redundant variables in it at the moment):
void GUI::createModel(){
for(int r = 0; r < 5; r ++ ){
if(c == 0){
for(int i = 0; i < 3; i ++ ){
child -> appendRow(child1);
item->appendRow(child);
}
}
model1->setItem(r, c, item);
}
}
void GUI::createModel(){
model1 = new QStandardItemModel(5, 2); //5 rows, 2 columns
for(int r = 0; r < 5; r ++ ){
QStandardItem* item = new QStandardItem(QString("File%0").arg(r)); //Top level
if(c == 0){
for(int i = 0; i < 3; i ++ ){
QStandardItem *child = new QStandardItem(
QString("Item %0").arg(i));
QStandardItem *child1 = new QStandardItem(
QString("Item %0").arg(i));
child -> appendRow(child1);
item->appendRow(child);
}
}
model1->setItem(r, c, item);
}
model1->setHorizontalHeaderItem(0, new QStandardItem("Name"));
model1->setHorizontalHeaderItem(1, new QStandardItem("Value"));
}
To copy to clipboard, switch view to plain text mode
The database (SQLite) holds video data. I want the 'root' to be the file name, and the children to be the names of the tables the values are from.
The result I want is :
|+file1
||+video -Video table
|||--frameRate
|||--codec
||+audio -audio table
|||-bitRate
|||-codec
|+file2
||+video -Video table
|||--frameRate
|||--codec
||+audio -audio table
|||-bitRate
|||-codec
So, I would be grateful if someone could guide me in a painless way of achieving this. I hope I've made myself clear.
Bookmarks