qt: fix race condition when SystemPalette is destroyed

As we don't control the destruction order of QML component, when scene is unloading
SystemPalette may be destroyed before ColorContext item that uses this palette, with
palette change not propagated in time.
This commit is contained in:
Pierre Lamot 2024-11-15 17:28:04 +01:00 committed by Steve Lhomme
parent 62ff2e006c
commit fca563901c

View File

@ -189,8 +189,7 @@ bool ColorContext::setInheritedPalette(SystemPalette* palette)
return false;
if (m_palette)
{
disconnect(m_palette, &SystemPalette::sourceChanged, this, &ColorContext::colorsChanged);
disconnect(m_palette, &SystemPalette::paletteChanged, this, &ColorContext::colorsChanged);
disconnect(m_palette, nullptr, this, nullptr);
}
m_palette = palette;
@ -199,6 +198,17 @@ bool ColorContext::setInheritedPalette(SystemPalette* palette)
{
connect(m_palette, &SystemPalette::sourceChanged, this, &ColorContext::colorsChanged);
connect(m_palette, &SystemPalette::paletteChanged, this, &ColorContext::colorsChanged);
connect(m_palette, &SystemPalette::destroyed, this, [this](){
if (m_parentContext)
{
if (m_hasExplicitPalette)
connect(m_parentContext, &ColorContext::paletteChanged, this, &ColorContext::setInheritedPalette);
setInheritedPalette(m_parentContext->m_palette);
}
else
setInheritedPalette(nullptr);
m_hasExplicitPalette = false;
});
}
else
m_initialized = false;