[Qt-interest] Confused about dataChanged Signal

Carsten Breuer CarstenBreuerQt at textwork.de
Sat Jul 3 00:34:58 CEST 2010


Hi Bill,
hi all,

> According the the v4.6.3 docs this signal is emitted when an existing
> item changes, in addition to that the implication is that there is no
> requirement for a setData(...) function on a read only model so with
> that in mind I'm of the opinion that all is taken care of internally for
> this RO model.

Right. setData is only needed if QTableView should be able
to write data in the model.

> However, I am seriously confused in that I never see any updates
> appearing in the table view with one exception, and that only appears
> when I click the view!

You have to tell QTableView that data has changed
with dataChanged(). I told you that before :-).
> 
> As I understand it (which must be incorrectly) I was assuming that the
> grid would automagically get updated when my thread modified the member
> variables having connected my Model's dataChanged(...) signal to my
> QTableView's dataChanged Slot.

Ups! Error. You don't have to do anything like that.
QTableView does all the magic when you call setModel!
You have to see models at the only interface you can
access from your data!

> Before I launch the thread I have set the FileName (column 0) to say
> "Processing File. Please wait..." however this change never appears in
> the grid unless I click the view (which forces an update).

Possible Errors:
- dataChanged not called.
- dataChanged with wrong indexes called.
- Roles not respected.
- Event queue of main thread blocked.

> Of course I have to ask, because I am changing the values of these
> variables does this then mean that my Model is in fact not RO but RW?

Did you check the Roles or not?
Did you return the data in a QVariant only if the role
is EditRole?


Best Regards,



Carsten



More information about the Qt-interest-old mailing list