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

Plugins: Deleted Modes are not removed, crash on click

    XMLWordPrintable

Details

    • e84bc5f81f05f306e63f86ea139a3b897d5877b1 (qt-creator/tqtc-qt-creator/5.0)

    Description

      This issue is about Qt Creator's Modes and adding/removing additional options to this sidebar using Qt Creators plugin framework.

      Qt Creator documentation mentions "Modes automatically register themselves with Qt Creator when they are created and unregister themselves when they are destructed."
      at https://doc.qt.io/qtcreator-extending/core-imode.html#details .

      Previously when a IMode was deleted (C++ delete operator), it would not be removed in from the mode sidebar in UI till you switched modes (untracked bug, QtC 4.x).
      However now, when a IMode is removed, the Mode button stays there forever. And when you click on it, a segmentation fault happens (due data deleted).
      Then QtCreator completly crashes.

      You can see the behaviour when running with gdb attached in the attached demo video.
      The Update mode is added by the plugin, when delete is called the Update button in the mode sidebar is supposed to be gone.

      Some example code:

      plugin header:

      class TestModePlugin : public ExtensionSystem::IPlugin {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TestModePlugin.json")
      .....
      private:
        Core::IMode *m_updateMode;
      .....
      }
      

      plugin implementation:

      bool TestModePlugin::initialize(const QStringList &arguments, QString *errorString) {
      	qDebug() << "TestModePlugin::initialize()";
      	m_updateMode = new UpdateMode(this, this);
      
      	qDebug() << "delete Mode in 10 seconds";
      	QTimer::singleShot(10000, [=]{
      		delete m_updateMode;
      		qDebug() << "deleted now";
      	});
      	return true;
      }
      

      mode header:

      #pragma once
      
      #include <QObject>
      #include <coreplugin/imode.h>
      
      namespace TestModePlugin {
      namespace Internal {
      
      class UpdateMode : public Core::IMode
      {
        Q_OBJECT
      
      public:
        UpdateMode(QObject *d, QObject *parent = nullptr);
        ~UpdateMode();
      private:
        QObject *m_d;
      };
      
      } // namespace Internal
      } // namespace TestModePlugin
      

      mode implementation:

      #include "updatemode.h"
      #include <coreplugin/coreconstants.h>
      #include <coreplugin/icontext.h>
      #include <QDebug>
      #include <utils/icon.h>
      
      namespace TestModePlugin {
      namespace Internal {
      
      UpdateMode::UpdateMode(QObject *d, QObject *parent) : IMode(parent) {
        setContext(Core::Context("Update", Core::Constants::C_NAVIGATION_PANE));
        setDisplayName(QLatin1String("Update"));
        m_d = d;
      
        const Utils::Icon MODE_UPDATE_CLASSIC(
                QLatin1String(":/qml/updateIcon.png"));
        const Utils::Icon MODE_UPDATE_FLAT({
                {QLatin1String(":/qml/mode_update_mask.png"), Utils::Theme::IconsModeHelpActiveColor}});
        const Utils::Icon MODE_UPDATE_FLAT_ACTIVE({
                {QLatin1String(":/qml/mode_update_mask.png"), Utils::Theme::IconsModeHelpActiveColor}});
      
        QIcon i = Utils::Icon::modeIcon(MODE_UPDATE_CLASSIC,
                                        MODE_UPDATE_FLAT, MODE_UPDATE_FLAT_ACTIVE);
      
        setIcon(i);
        setPriority(0);
        setId("Mode.Update");
        setWidget(new QWidget());
      }
      
      UpdateMode::~UpdateMode() {
        delete m_widget;
      }
      
      } // namespace Internal
      } // namespace TestModePlugin
      
      

      --> Bugfix for delete to properly delete the mode and hide it from UI
      --> Is there a method available to manually remove/delete a IMode? As far I discovered this is private implementation and not reachable by plugins.

      Attachments

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

        Activity

          People

            con Eike Ziller
            de-live-gdev Gregor Santner
            Votes:
            6 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes