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

Crash in ButtonGroup when removing items from a model using beginRemoveRows()/endRemoveRows()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.9.3
    • 5.10
    • Quick: Controls 2
    • None
    • Windows 10
    • 3f1229bb7bfd45fdc09ce8c2a16cc59e322d5d1c

    Description

      I have a ListView with ItemDelegates whose model is set to a custom model. A ButtonGroup monitors the ListView's delegates. When removing items from the model using beginRemoveRows()/endRemoveRows(), I get a crash:

      1  QQuickAbstractButton::setChecked             qquickabstractbutton.cpp       554  0x7fffa4501711 
      2  QQuickButtonGroup::setCheckedButton          qquickbuttongroup.cpp          277  0x7fffa451f2bb 
      3  QQuickButtonGroupPrivate::_q_updateCurrent   qquickbuttongroup.cpp          205  0x7fffa451ffb9 
      4  QQuickButtonGroup::qt_static_metacall        moc_qquickbuttongroup_p.cpp    140  0x7fffa451ef1d 
      5  QMetaCallEvent::placeMetaCall                qobject.cpp                    504  0x72123c51     
      6  QObject::event                               qobject.cpp                    1246 0x7211c6ff     
      7  QCoreApplicationPrivate::notify_helper       qcoreapplication.cpp           1171 0x720c5a7e     
      8  doNotify                                     qcoreapplication.cpp           1111 0x720c71e8     
      9  QCoreApplication::notify                     qcoreapplication.cpp           1098 0x720c3221     
      10 QGuiApplication::notify                      qguiapplication.cpp            1696 0x7fff980bacc9 
      11 QCoreApplication::notifyInternal2            qcoreapplication.cpp           1021 0x720c4b46     
      12 QCoreApplication::sendEvent                  qcoreapplication.h             234  0x720cfba2     
      13 QCoreApplicationPrivate::sendPostedEvents    qcoreapplication.cpp           1696 0x720c645d     
      14 QEventDispatcherWin32::sendPostedEvents      qeventdispatcher_win.cpp       1079 0x7218201a     
      15 QWindowsGuiEventDispatcher::sendPostedEvents qwindowsguieventdispatcher.cpp 82   0x7fffa4936574 
      16 qt_internal_proc                             qeventdispatcher_win.cpp       239  0x7217fe1b     
      17 CallWindowProcW                              USER32                              0x7fffd370bc50 
      18 DispatchMessageW                             USER32                              0x7fffd370b5cf 
      19 QEventDispatcherWin32::processEvents         qeventdispatcher_win.cpp       630  0x7218078d     
      20 QWindowsGuiEventDispatcher::processEvents    qwindowsguieventdispatcher.cpp 74   0x7fffa4936534 
      21 QCoreApplication::processEvents              qcoreapplication.cpp           1254 0x720c28d6     
      22 QTest::qWait                                 qtestsystem.h                  65   0x7ff6629629ff 
      23 tst_App::openClose                           tst_app.cpp                    57   0x7ff6629634a4 
      24 tst_App::qt_static_metacall                  tst_app.moc                    75   0x7ff662963263 
      25 QMetaMethod::invoke                          qmetaobject.cpp                2306 0x720d4121     
      26 QMetaMethod::invoke                          qmetaobject.h                  124  0x71cbacb9     
      27 QTest::TestMethods::invokeTestOnData         qtestcase.cpp                  895  0x7fffb0c3a0ea 
      28 QTest::TestMethods::invokeTest               qtestcase.cpp                  1077 0x7fffb0c39929 
      29 QTest::TestMethods::invokeTests              qtestcase.cpp                  1393 0x7fffb0c39211 
      30 QTest::qRun                                  qtestcase.cpp                  1833 0x7fffb0c358e6 
      31 QTest::qExec                                 qtestcase.cpp                  1720 0x7fffb0c359ea 
      32 main                                         tst_app.cpp                    62   0x7ff6629634ff 
      33 invoke_main                                  exe_common.inl                 65   0x7ff66296a7c4 
      34 __scrt_common_main_seh                       exe_common.inl                 253  0x7ff66296a687 
      35 __scrt_common_main                           exe_common.inl                 296  0x7ff66296a54e 
      36 mainCRTStartup                               exe_main.cpp                   17   0x7ff66296a7e9 
      37 BaseThreadInitThunk                          KERNEL32                            0x7fffd3872774 
      38 RtlUserThreadStart                           ntdll                               0x7fffd4ef0d51                                                                                  
      

      Snippets (minimal reproducible project attached):

      layermodel.cpp
      // ...
      
      #define CRASH
      
      void LayerModel::clearLayers()
      {
      #ifdef CRASH
          while (!mLayers.isEmpty()) {
              beginRemoveRows(QModelIndex(), 0, 0);
              mLayers.takeAt(0);
              endRemoveRows();
          }
      #else
          beginResetModel();
          mLayers.clear();
          endResetModel();
      #endif
      }
      
      // ...
      
      main.qml
              // ...
      
              ButtonGroup {
                  objectName: "layerPanelButtonGroup"
                  buttons: listView.contentItem.children
              }
      
              ListView {
                  id: listView
                  objectName: "layerListView"
                  anchors.fill: parent
                  boundsBehavior: ListView.StopAtBounds
                  clip: true
      
                  model: LayerModel {
                      id: layerModel
                  }
                  // Works:
          //        model: 3
      
                  delegate: ItemDelegate {
                      objectName: "itemDelegate" + index
                      checkable: true
                      checked: index == 0
                  }
              }
      
              // ...
      

      Attachments

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes