PDA

View Full Version : QTableView changing item text (signal)?



AlphaWolfXV
27th December 2011, 15:21
Hello all,
I have a simple (hopefully) question regarding QTableView. I have one in a form, and would like to get a signal from it when the text inside one of the cells changes. I have it loading with a QSqlTableModel, from an SQL database and I would like some kind of notification when the user changes one of the rows data.

Any thoughts?
I am using QT 4.7.4, creator 2.4, on Windows 7 32bit.
Thanks,
AlphaWolfXV

kunashir
28th December 2011, 09:20
Hello.
If I rigth understand you, try to use next signal of QSqlTableModel -
void dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )
from Assistant:
This signal is emitted whenever the data in an existing item changes.

AlphaWolfXV
28th December 2011, 13:40
Thank you Kunashir, I will give that a try!

On a related note, I have tried to subclass QItemDelegate as in the spinbox example... This does "catch" the edited text and will update the model upon "enter". However, I would like to emit a signal from the subclass (a formDirty() signal) which would let the user know they are about to change data in the sql database. (Similar to MSAccess table/form editing). Any thoughts...
I currently added a signal void dirty(); to the subclassed h file [LineEditDelegate.h] and emit it from the cpp when the editor is called, but now I receive the error on compiling:

passing const LineEditDelegate as 'this' argument in void LineEditDelegate::dirty() discards qualifier
I am unclear as to what this means!
Thanks,
AlphaWolfXV

kunashir
29th December 2011, 05:09
Hello!
AlphaWolfXV, for your task You may use delegate, but if use only text, it is more difficult.
From error: I suggest Your try change const variable - LineEditDelegate.

AlphaWolfXV
30th December 2011, 14:05
kunashir,
Thank you for your info. I will give that a try!
Thanks,
AlphaWolfXV