What exactly has changed when QStandardItemModel itemChanged is signaled

QStandardItemModel has a signal that is emitted when the data of an element changes. Usually we attach a handler for this signal and do all the work in the handler routine.

Such a manual procedure only gets a pointer to an element. Using this pointer, you can access element data. However, we don’t know what exactly has changed ... we just updated the value.

If the data of an element has several roles, I want to be able to precisely determine which role (data) has been changed and what the previous value was.

+4
source share
2 answers

In general, QStandardItemModel designed for very simple data modeling. If you want to do more advanced things as you describe, you should study the subclasses of QAbstractItemModel or one of them is abstract derivatives: Models / lookup classes

This may seem like a lot of work, but use examples and direct links: Model / Programming Preview , Model Subclass , and rewards will be great.

+5
source

This is not possible with standard Qt signals. I suggest adding another signal for this.

For my own models, I usually use this approach: I have a root instance containing pointers to all parts of my data model. My model elements use this root instance to send signals of type

 itemChanged(item, attribute, oldValue, newValue) 

for simple properties. The same goes for lists, etc .; only here I have several signals depending on the action, for example:

 itemAdded(list, item, index) 

[EDIT] QT signal processing is very simple. Usually it says only "something has changed." There is no support, "what exactly has changed?" since you don’t need it most of the time. Therefore, if you need this information, you must do it yourself. You cannot use one role because the roles must be supported by something in your element. What you can do is add change information to your objects and read when the role is requested. But this is not what is supported out of the box.

0
source

All Articles