Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-40462

QTreeWidget gets corrupted when restoring a state saved by a Qt4 program

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 5.5.0
    • 5.3.0, 5.3.1
    • None
    • Windows, MinGW, gcc 4.9.0, Qt 5.3.1
    • Fix reading: 088e9bbb4bb1a0368010692c8c55425c880858e7 (dev, 6.8.2014, 5.4) e0a8b5ce88bc50440dcec2fe3a86d83e2a7dc7b0

      We recently migrated to Qt5 (5.3.0 then 5.3.1).
      Since then, we regularly have a problem we calling header()->restoreState() in our widgets.
      It seems that it sometimes saved a "corrupted" state and when we try to restore it, nothing in the tree can be selected (item cannot be selected) and the context menu of the header isn't displayed when right clicking on it.

      Worth to note that restoreState returns true, so we can't rely on this to know if it's broken.

      I tried to manually ui->treeWidget->setEnabled(true); and few other things but that didn't help.

      We save the current state like this:

      QSettings settings(QString("C:/SomePath/Settings/Pref.ini"), QSettings::IniFormat);
      settings.setValue("prefName", ui->treeWidget->header()->saveState());
      

      And restore it like this:

      ui->treeWidget->header()->restoreState(settings.value("prefName").toByteArray());
      

      The pref saved in the ini file:

      "@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x1\0\0\0\x1\0\0\0\f\x1\0\0\0\0\0\0\0\0\0\0\0\xf\x4\x41\0\0\0\x3\0\0\0\xe\0\0\0\x64\0\0\0\b\0\0\x2X\0\0\0\x2\0\0\0\x64\xff\xff\xff\x3\0\0\0\xf\x1\x1\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\x64\xff\xff\xff\xff\0\0\0\x81\0\0\0\0\0\0\0\xf\0\0\0\xde\0\0\0\x1\0\0\0\0\0\0\0P\0\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\x1\0\0\0\0\0\0\0P\0\0\0\x1\0\0\0\0\0\0\0\xc8\0\0\0\x1\0\0\0\0\0\0\0\x9c\0\0\0\x1\0\0\0\0\0\0\0g\0\0\0\x1\0\0\0\0\0\0\0P\0\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\x1\0\0\0\0\0\0\x2X\0\0\0\x1\0\0\0\0\0\0\x2X\0\0\0\x1\0\0\0\0\0\0\0\x64\0\0\0\x1\0\0\0\0\0\0\0\x61\0\0\0\x1\0\0\0\0\0\0\x3=\0\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\x1\0\0\0\0\0\0\x3\xe8)"
      

      I created a small GUI project with nothing but a treeWidget, and restoring with this value reproduces the error (i.e. items cannot be selected, even if restoreState returns true)

      We didn't have this problem with Qt 4.8

        1. qtbug40462_bailout.diff
          2 kB
          Friedemann Kleint
        2. qtbug40462_diag.diff
          4 kB
          Friedemann Kleint
        3. qtbug40462_log.txt
          1 kB
          Friedemann Kleint
        4. qtbug40462.zip
          2 kB
          Friedemann Kleint
        5. Settings_QTBUG-40462.zip
          0.5 kB
          Arnaud Bienner
        6. Settings_QTBUG-40462-2.zip
          0.5 kB
          Arnaud Bienner
        7. TestRestoreState.zip
          5 kB
          Arnaud Bienner
        8. TestRestoreState-2.zip
          5 kB
          Arnaud Bienner
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kleint Friedemann Kleint
            arnaud.bienner Arnaud Bienner
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: