Unsolved Some questions about the QAbstractTableModel dataChanged signal
-
Hi,
in my project centered around tableviews and abstracttablemodels, whose number is being determined by loading some json-data, i have some rows consisting of boolean values. The ones set to "true" get counted and displayed in the last row but the result will not be shown, because I somehow can't figure out the correct syntax for it. I suppose that usually only one cell is being updated, when the signal from the setData function is being emitted like this:
emit dataChanged(index, index);
But I want to be able to also display the value on the same column and the last line, so something like:
emit dataChanged(index(row, col), index(lastRow, col)); ```
should work. But I encounter a "No matching call error".
The other question is related to the first. For some of the boolean columns i'd like to know how many cells are being set to true regarding all tableviews / abstracttablemodels. What might be the best way to achieve this? Connecting to the dataChanged signals of all the other models? Or would it be more suitable to add a custom signal?
Kind regards,
Andreas
-
Hi,
Any chance you have a local variable named index and that you are trying to call the function of the same name ?
As your multiple models, yes, you can connect to the dataChanged signal and only act if the change includes one or more of your Boolean column.
-
@SGaist well it should be the index parameter of setData(const QModelIndex &index, const QVariant &value, int role), i suppose. Or should I declare another QModelIndex locally?
Regarding the connection to the dataChanged signals, i must think about how to avoid too much confusion, because, if one value changes, all the other tables must be affected....
-
Ok, after a look into the documentation, i could solve the first question. I added a local QModelIndex() and assigned the index variable of the model to it:
code_t QModelIndex bottomRight = this->index(lastRow, col, QModelIndex());
I don't know why i cannot use the parameter of the function itself, because i found a lot of examples suggesting just that. Anyway, the dataChanged function now works as expected and looks like this in my case:
emit dataChanged(index, bottomRight);
-
@andi456 said in Some questions about the QAbstractTableModel dataChanged signal:
I don't now why i cannot use the parameter of the function itself,
The one is a parameter of type QModelIndex, the other a function from QAbstractItemModel.
-
@Christian-Ehrlicher Thanks for the clarification. Anyway, there're examples on the internet that seem to suggest that one could also use the parameter of setData() in order to obtain the same thing.
-
It depends on what you want to do...