QHeaderView::restoreState(): Add sanity check.

Read data into local variables and apply only after a check.

Task-number: QTBUG-40462
Change-Id: Id06060d0d5b0eafc2d303526a86d552ff5747a72
Reviewed-by: David Faure <david.faure@kdab.com>