You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, February 14th 2011, 11:40am

Add a Coumn to a QSqltablemodel to hold non DB Data

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.

QSqlFieldfield("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(intix=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.

2

Monday, February 14th 2011, 7:20pm

There is a bug in QSqlTableModel::insertColumn with Qt 4.7.1 and previous versions.
QSqlQueryModel::insertColumn seems to work fine, but it's a read-only model (unless you subclass it).