PDA

View Full Version : Qtableview and sql



kuntagp
9th December 2011, 17:32
i'm using a Qtableview with an hiden invoice_id column to manage invoices row, i would like to know if there is a way
to change the invoice_id column value for each row before commiting thanks in advance?

pkj
10th December 2011, 14:37
If you don't want to show, why to have it in first place??? QTableView works on a model. According to the logic, you can change the requisite in setData function of model. Why does it feel to me you have an overhang of lot of asp.net tables before you came here, or perhaps you just didn't explain it well enough :)

ChrisW67
12th December 2011, 04:36
If you don't want to show, why to have it in first place???
The obvious response is that a single model may serve multiple views and not all views necessarily need (or even should if columns are restricted to certain users) to show everything in the model. It can also be useful to have a column that is hidden in release version but visible during debug (e.g. an underlying database ID).


i would like to know if there is a way to change the invoice_id column value for each row before commiting thanks in advance?
You can call setData() on model indexes that reference columns that a view is not showing. You do need to work out exactly where (inside or outside the model) and when (on insert only, update only, both, what about delete or new rows as yet uncommited) the value should be changed. Inside the model: do anything you like in the model's setData(), just make sure the relevant signals are emitted so views stay synchronised. Outside the model: if you have a delegate on the table then setModelData() may be a good place. If you are referring to commiting to an underlying database then the QSqlTableModel::beforeInsert(), beforeUpdate(), and primeInsert() signals can be useful.

kuntagp
17th December 2011, 21:26
Thanks Chris your post help me a lot

kuntagp
22nd December 2011, 05:23
Here is a little example:

model->setData(model->index(row, 1), QVariant(id));