Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-25310

MainWindow ContextObject handling causes crashes for custom plugins

    XMLWordPrintable

Details

    • Windows
    • 8875c59021586bf66b38299873dd05f440a99665 (qt-creator/qt-creator/4.14)

    Description

      We are building plugins for QtCreator and one of the changes in QtCreator's code is causing crashes for us.

      Basically the problem lies in MainWindow::addContextObject function and in destruction order.

      MainWindow::addContextObject does this:

       

      connect(context, &QObject::destroyed, this, [this, context] { removeContextObject(context); });

       

      This code allows removeContextObject function to access m_contextWidgets even after  MainWindow destructor has finished and m_contextWidgets is destroyed.

       

      Happens when MainWindow::addContextObject is called by a grand-grand-grand.... child widget, which gets destroyed by MainWidget base class (that destroys all children).

      As you see m_contextWidgets is destroyed by that time.

       

      It works for QtCreator code because you do manual deletion in MainWindow destructor and does not let the object to be automatically destroyed by base class. If you would, it would crash for you as well (widgets that have Context registered).

       

      Another way to handle this is to delete the widgets before MainWindow manually and not let the widget tree to do the job. This is what you do with HelpWidget.

       

       

      ExtensionSystem::IPlugin::ShutdownFlag HelpPlugin::aboutToShutdown()
      {
          delete dd->m_externalWindow.data();
      
          delete dd->m_centralWidget;
          dd->m_centralWidget = nullptr;
      

       

      If you remove the manual deletion of dd->m_centralWidget and let the widget tree to do the removal, then it does crash for you as well. (note that you have to comment out the whole HelpWidget destructor as well as it gets some other crashes before you reach this).

       

      But this seems incorrect that I just can't let the widget tree to do the deletion of all the widgets automatically.

      Wasn't a problem before this was introduced:

      connect(context, &QObject::destroyed, this, [this, context] { removeContextObject(context); });
      

      Can you fix so that we don't have to hack around it in our code and let the widget tree naturally delete everything?

       

      Attachments

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

        Activity

          People

            con Eike Ziller
            arminr Armin Riiet
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes