PDA

View Full Version : Add a Non DB column, to SqlTableModel, for External Data.



AndyD1965
14th February 2011, 12:38
what i need is to add a extra column to a QSqlTableModel built from a Select query , to hold data that is not in the DataBase. to be displayied, in a table format on a QT screen , so
QT Version 4.7.1 (Operating System - XP sp3)
DB : MYsql
Table i require is
Column 1 = ID, (from select query)
Column 2 = GallyUNC (from select query)
Column 3 = Image (held on another server, NOT in Database)
I Have tried this,
1.
model->insertColumn(2);
model->setHeaderData(2,Qt::Horizontal,"Image",Qt::DisplayRole);
Which results in the following debug output , so it has added something to SqlTableModel

0:" QSqlField("Id", qlonglong, length: 20, precision: 0, required: no, generated: yes, typeID: 8) "140507771740"
" 1:" QSqlField("GalleryUNC", QString, length: 300, precision: 0, required: no, generated: yes, typeID: 253) "dddd"
" 2:" QSqlField("", , generated: no) ""
2. Also this.
QSqlField field("Image",QVariant::String);
field.setName("Image");
field.setGenerated(true);
field.setReadOnly(false);
field.setLength(300);
field.setType(QVariant::String);
field.setPrecision(0);
field.setRequired(false);
field.setValue("imagef");
for (int ix = 0 ; ix < model->rowCount() ; ++ix)
{
model->record(ix).append(field);
qDebug() << model->record(ix);
}
}
But nothing seems to be working, so has any one got any ideas where i am going wrong, or examples, that can point me in the right direction. to merge DB data with none DB data and display it.

d_stranz
14th February 2011, 16:59
Why don't you use a custom QSortFilterProxyModel to interface between your SQL model and the view? Override the columnCount() and data() methods to add your extra column and to supply the data for it, and make sure that the filterAccepts...() methods return the right answers.