forked from qt-creator/qt-creator
Fix the "Cannot remove a null widget" warning
After the 867c0b8d8a53974074b1fff5b132f3ae9f150066 got integrated into qtbase, Qt started issuing a warning on Creator shutdown. The reason is that mode's widget might be deleted before the mode's destruction. Deleting the mode's widget removes it automatically from the contained stacked layout of the mode manager. This means that the indices inside the stacked layout and those inside the ModeManager's d->m_modes list are now out of sync. FancyTabWidget::removeTab() can't find the right widget for the passed index now or returns wrong widget for it. The fix is to remove removeMode() method (and in turn some more unused now). The context objects don't need to be removed on shutdown, and the remaining mode's widgets will be deleted by Qt itself when the main windows is destroyed. Fixes: QTCREATORBUG-25925 Change-Id: I70c2773eea2984c5d06ce3bf71a4271b267efbe0 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -551,12 +551,6 @@ void FancyTabWidget::insertTab(int index, QWidget *tab, const QIcon &icon, const
|
|||||||
m_tabBar->insertTab(index, icon, label, hasMenu);
|
m_tabBar->insertTab(index, icon, label, hasMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyTabWidget::removeTab(int index)
|
|
||||||
{
|
|
||||||
m_modesStack->removeWidget(m_modesStack->widget(index));
|
|
||||||
m_tabBar->removeTab(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FancyTabWidget::setBackgroundBrush(const QBrush &brush)
|
void FancyTabWidget::setBackgroundBrush(const QBrush &brush)
|
||||||
{
|
{
|
||||||
QPalette pal;
|
QPalette pal;
|
||||||
|
|||||||
@@ -109,12 +109,6 @@ public:
|
|||||||
updateGeometry();
|
updateGeometry();
|
||||||
}
|
}
|
||||||
void setEnabled(int index, bool enabled);
|
void setEnabled(int index, bool enabled);
|
||||||
void removeTab(int index)
|
|
||||||
{
|
|
||||||
FancyTab *tab = m_tabs.takeAt(index);
|
|
||||||
delete tab;
|
|
||||||
updateGeometry();
|
|
||||||
}
|
|
||||||
void setCurrentIndex(int index);
|
void setCurrentIndex(int index);
|
||||||
int currentIndex() const { return m_currentIndex; }
|
int currentIndex() const { return m_currentIndex; }
|
||||||
|
|
||||||
@@ -148,7 +142,6 @@ public:
|
|||||||
FancyTabWidget(QWidget *parent = nullptr);
|
FancyTabWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu);
|
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu);
|
||||||
void removeTab(int index);
|
|
||||||
void setBackgroundBrush(const QBrush &brush);
|
void setBackgroundBrush(const QBrush &brush);
|
||||||
void addCornerWidget(QWidget *widget);
|
void addCornerWidget(QWidget *widget);
|
||||||
void insertCornerWidget(int pos, QWidget *widget);
|
void insertCornerWidget(int pos, QWidget *widget);
|
||||||
|
|||||||
@@ -125,14 +125,6 @@ IMode::IMode(QObject *parent) : IContext(parent)
|
|||||||
ModeManager::addMode(this);
|
ModeManager::addMode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Unregisters the mode from \QC and destroys it.
|
|
||||||
*/
|
|
||||||
IMode::~IMode()
|
|
||||||
{
|
|
||||||
ModeManager::removeMode(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IMode::setEnabled(bool enabled)
|
void IMode::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (m_isEnabled == enabled)
|
if (m_isEnabled == enabled)
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ class CORE_EXPORT IMode : public IContext
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
IMode(QObject *parent = nullptr);
|
IMode(QObject *parent = nullptr);
|
||||||
~IMode() override;
|
|
||||||
|
|
||||||
QString displayName() const { return m_displayName; }
|
QString displayName() const { return m_displayName; }
|
||||||
QIcon icon() const { return m_icon; }
|
QIcon icon() const { return m_icon; }
|
||||||
|
|||||||
@@ -275,19 +275,6 @@ void ModeManagerPrivate::enabledStateChanged(IMode *mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModeManager::removeMode(IMode *mode)
|
|
||||||
{
|
|
||||||
const int index = d->m_modes.indexOf(mode);
|
|
||||||
d->m_modes.remove(index);
|
|
||||||
if (d->m_startingUp)
|
|
||||||
return;
|
|
||||||
|
|
||||||
d->m_modeCommands.remove(index);
|
|
||||||
d->m_modeStack->removeTab(index);
|
|
||||||
|
|
||||||
d->m_mainWindow->removeContextObject(mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Adds the \a action to the mode selector's tool bar.
|
Adds the \a action to the mode selector's tool bar.
|
||||||
Actions are sorted by \a priority in descending order.
|
Actions are sorted by \a priority in descending order.
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ private:
|
|||||||
static void extensionsInitialized();
|
static void extensionsInitialized();
|
||||||
|
|
||||||
static void addMode(IMode *mode);
|
static void addMode(IMode *mode);
|
||||||
static void removeMode(IMode *mode);
|
|
||||||
void currentTabAboutToChange(int index);
|
void currentTabAboutToChange(int index);
|
||||||
void currentTabChanged(int index);
|
void currentTabChanged(int index);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user