PDA

View Full Version : Clearing data model



db
14th February 2008, 16:16
I have a QStandardDataModel that is associated with a table view. There is a rest button on the form. When the reset is clicked it calls a method that clears the data model using clear().

I thought that this would eliminate eveything associatd with the model so that the next time I use the model I'm starting at the begining. That is not the case.

There are 4 columns of data. After the clear(), when I populated the model again I have 8 columns (last 4 being empty). And this continues.

How do I effectively clear the data model so that on the next resue it only displays the data set and not empty items.

jpn
14th February 2008, 16:54
I thought that this would eliminate eveything associatd with the model so that the next time I use the model I'm starting at the begining. That is not the case.

There are 4 columns of data. After the clear(), when I populated the model again I have 8 columns (last 4 being empty). And this continues.
Are you sure it's not a bug in your code? This is what QStandardItemModel::clear() docs promise:

Removes all items (including header items) from the model and sets the number of rows and columns to zero.

db
14th February 2008, 18:33
I been through the code several times... but I'll go back through it again. I agree, I thought that that was all i needed to do to clear it.

db
14th February 2008, 20:03
Further investigation of my code shows that the clear() is not completely working because I set header labels uing model.setHorizontalHeaderLabel().

Appearently cleaer() does not get rid of the header labels. I have been going through the documentation and can't seem to find the correct call to clear the header labels so that the clear() will clear the table.

What is the call?

jpn
14th February 2008, 22:16
Hmm, but calling setHorizontalHeaderLabels() again and again won't increase the column count, does it? Could you write a simple and small test application which shows the problem you're encountering?

db
16th February 2008, 14:02
OK. I have provided a stripped version of my code. It has only the items needed to show the problem. If you comment out the setHorizontalHeader call you'll set that it acts OK. Setting the header causes the error.

Thanks

jpn
16th February 2008, 14:10
"QStringList headerLabels" is a member variable. Three strings are being added every time CFlightPlan::createModel() gets called. First time it contains properly 3 items, second time it contains 6 items and so on...