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

QMainWindow::restoreState() partially restore incorrect state

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Not Evaluated Not Evaluated
    • 4.6.0
    • 4.5.3
    • Widgets: Main Window
    • None

      QMainWindow::restoreState() should return false and don't do anything if the structure of the QMainWindow does not match the state.

      It is not the case, QMainWindow::restoreState() returns true, and the QMainWindow is in a partially restored state. This can leads to crashes when the QMainWindow is modified after QMainWindow::restoreState().

      Here is a test case for this issue:

      #include <QtTest/QtTest>
      #include <QtGui>

      class Test : public QObject{
      Q_OBJECT

      private slots:
      void restoreStateFailIfNotMatch() {
      const QRect geometry(30, 40, 50, 60);
      QByteArray state;

      { QMainWindow main; QDockWidget *dock = new QDockWidget("Dock1"); main.addDockWidget(Qt::LeftDockWidgetArea, dock); main.setGeometry(geometry); state = main.saveState(); } { QMainWindow main; main.setGeometry(geometry); bool ok = main.restoreState(state); QVERIFY(!ok); }

      }
      };

      QTEST_MAIN(Test)
      #include "test.moc"

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            vfm Thierry Bastian (closed Nokia identity) (Inactive)
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes