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

QStackedLayout::setCurrentIndex() may crash with very dynamic GUIs

    XMLWordPrintable

Details

    • 18f9eb797bffe8626f1edeca3c88f80dae0da8d7 (5.1), 5a58067a8ed92553182467a3522aff7747a22cad (4.8)

    Description

      The method QStackedLayout::setCurrentIndex() does the following

      1. Store the window's focusWidget() in a local variable
      2. hide the old widget
      3. show the new widget
      4. try to set a sensible new focus widget

      When a widget creates its internal structure in its showEvent() and tears down some internal widgets in the hideEvent(), it can happen that the old focus widget is destroyed in step 2 and step 4 uses a dangling pointer.

      Solution: Use a QPointer instead:

      --- qstackedlayout.cpp.old      2011-03-21 08:10:35.117951000 +0100
      +++ qstackedlayout.cpp  2011-03-21 07:57:43.263064000 +0100
      @@ -301,7 +301,7 @@
               parent->setUpdatesEnabled(false);
           }
      
      -    QWidget *fw = parent ? parent->window()->focusWidget() : 0;
      +    QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0;
           if (prev) {
               prev->clearFocus();
               if (d->stackingMode == StackOne)
      

      Attachments

        1. qt501.png
          qt501.png
          451 kB
        2. sl.tgz
          0.7 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            smd Jan Arve
            bgehrmann Bernd Gehrmann
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes