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

Crash from stylesheet due to dangling widget pointers in cache

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.0
    • 4.6.3, 4.7.0
    • Widgets: Style Sheets
    • None
    • Windows (should happen on other platforms as well)
    • 7b63ce043dfaec5ec83d938b1cea8ee0ead614ff

    Description

      Style sheet keeps track of the widgets in cache using the destroyed() signal from QObject. In this example the style sheet recreates the QStyleSheetStyle internally and keeps the old cache, but those objects were connected to the destroyed QStyleSheetStyle object. So if one of those widgets are destroyed, the cache wont get updated.

      #include <QtGui>
      #include <qdebug.h>
      
      class Widget : public QWidget
      {
      public:
          Widget(QWidget *parent = 0);
          ~Widget();
      };
      
      const char* pszStyleSheet = "* { color: red; }";
      
      Widget::Widget(QWidget *parent)
          : QWidget(parent)
      {
          QVBoxLayout* pLayout = new QVBoxLayout(this);
          QCheckBox* pCheckBox = new QCheckBox(this);
          pLayout->addWidget(pCheckBox);
          setLayout(pLayout);
      
          QString szStyleSheet = QLatin1String(pszStyleSheet);
          qApp->setStyleSheet(szStyleSheet);
          qApp->setStyle(QStyleFactory::create(QLatin1String("Windows")));
      }
      
      Widget::~Widget()
      {
      
      }
      
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          Widget *w = new Widget();
          delete w;
          w = new Widget();
          w->show();
      
          return a.exec();
      }
      

      Attachments

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

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            anshaw Andy Shaw (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes