How to inform a QTableView about changes in the underlying QAbstractTablemodel?
Hi!
I'm developing a customer library. I have a model and a view class:
Code:
{
//...
public slots:
void setSeachString
(const QString & str
){ _vec_restricted.clear();
foreach(Customer * c, _vec_all)
if(c->contains(str)) _vec_restricted.append(c);
}
private:
QVector<Customer*> _vec_all;
QVector<Customer*> _vec_restricted;
}
{
//...
}
Ok, in order to find quickly an entry, I have a LineEdit whose textChanged signal is connected to the setSearchString(...) method.
So anytime the text changes, drastic changes happen to my model.
How can I inform the view that an update is necessary?
Also I do not want to remove the rows one by one.
Thnaks in advance,
Olli
Re: How to inform a QTableView about changes in the underlying QAbstractTablemodel?
take a look at QAbstractItemModel::dataChanged() signal or maybe in your case QAbstractItemModel::reset() method would be better.
Re: How to inform a QTableView about changes in the underlying QAbstractTablemodel?
Hi!
Thanks for your reply.
The questio I have is on what data the dataChanged signal refers.
Lots of "rows" in my library can disappear and lots can appear.
Eg if I had all entries before and now select only those containing the letter S, what shall I signal then? A dataChanged on all non-S-entires?
Re: How to inform a QTableView about changes in the underlying QAbstractTablemodel?
if you insert rows or remove them there are signals for that: QAbstractItemModel::rowsInserted() and QAbstractItemModel::rowsRemoved(). And when you are for example inserting rows then you are emmiting rowsAboutToBeInserted then isert them and then emit rowsInserted. Please refer to Qt Examples & Demos and Qt Assistant, where whole item's change, insertion an removal is expalind clear.
Re: How to inform a QTableView about changes in the underlying QAbstractTablemodel?
Thank you for your replies so far.
I have (temporarily) solved the problem for now by simply calling QAbstractTabelModel::reset(). I will have to come back to this problem eventually later when dealing with more than a only few example customer datas.
Thank you all!