tags:

views:

383

answers:

4

I can't narrow down this bug, however I seem to have the following problem: - saveState() of a horizontalHeader() - restart app - Modify model so that it has one less column - restoreState() - Now, for some reason, the state of the headerview is totally messed up. I cannot show or hide any new columns, nor can I ever get a reasonable state back

I know, this is not very descriptive but I'm hoping others have had this problem before.

A: 

I would expect it to break if you change the model! Those functions save and restore private class member variables directly without any sanity checks. Try restoring the state and then changing the model.

Judge Maygarden
I've tried this as well but when I change the model, then all the previous header view state disappears!
cheez
I would expect that to be the case. How should the view of a one model be automatically adapted to a different model? The Qt library has know way of knowing the relationship between the new sections.
Judge Maygarden
A: 

I personally never use saveState()/restoreState() in any Qt widget, since they just return a binary blob anyway. I want my config files to be human-readable, with simple types. That also gets rid of these kind of problems.

In addition, QHeaderView has the naughty problem that restoreState() (or equivalents) only ever worked for me when the model has already been set, and then some time. I ended up connecting to the QHeaderView::sectionCountChanged() signal and setting the state in the slot called from it.

Sure, I'd love to but I'm pretty sure that QHeaderView does not expose enough information for me to do the same things as saveState would do :-(
cheez
A: 

For QMainWindow, the save/restoreState takes a version number. If it's the same with table view, you need to use that to avoid conflicts if you change the data/model somehow.

See the doc for QMainWindow::restoreState as an example.

Marcus Lindblom
+1  A: 

Here is the solution I made using Boost Serialization: http://codepad.org/2gPIMPYU

It handles new and removed columns, more or less. Works for my use cases.

cheez