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

QComboBox with null view crashing application

    XMLWordPrintable

Details

    • Windows
    • 9965f9a19 (dev), cfee3304b (6.8), 91b62e4bd (tqtc/lts-6.5)

    Description

      I have a large Qt application built with PyQt6 which dynamically creates and deletes widgets including several QComboBoxes which appear in a QTreeWidget (via QTreeWidget.setItemWidget). The application works fine in Linux, but in Windows it randomly crashes when updating widgets. I built Qt with debug information and ran my application through the debugger and found that it crashes in itemvews.cpp in the function:

      int QAccessibleTable::childCount() const 

      The problem is that Qt has the following code:

      int QAccessibleTable::childCount() const
      {
          const QAbstractItemView *theView = view();
          const QAbstractItemModel *theModel = theView->model();
          if (!theModel)
              return 0; 
      ...

      Somehow the object that is calling this, which is a QComboBox, has a NULL object returned by the view() function. If I simply do a null check of what is returned by the view() function, as the following code shows, then my program crash goes away completely:

      int QAccessibleTable::childCount() const
      {
          const QAbstractItemView *theView = view();
          // New null check added (similarly to how theModel is checked below)
          if (!theView)
              return 0;
          const QAbstractItemModel *theModel = theView->model();
          if (!theModel)
              return 0; 

      I believe the fix is sound and will not cause any problems and it prevents my application from crashing now. I understand that there may be an underlying problem somewhere else causing view() to return NULL, possibly in PyQt and nothing to do with my application, but for sake of being practical this is the fix that we are implementing.

      I would really appreciate it one of the Qt contributors could add this fix into the code base since we want to keep our Qt version up to date with the newest release and don't want to have to patch the code every time we update. I don't have time to become a Qt contributor myself to shepherd this through.

      Thanks

      p.s. I have the same identical crash in Qt 5.15 as well as in 6.6.2 - I thought that maybe upgrading to Qt6 would fix my problem but it did not and so I have debugged this further and found the cause.

       

      Attachments

        For Gerrit Dashboard: QTBUG-129582
        # Subject Branch Project Status CR V

        Activity

          People

            vhilshei Volker Hilsheimer
            jeremyg Jeremy Gribben
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes