1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-04-01 02:42:39 +08:00

fix crash

This commit is contained in:
Syarif Fakhri 2022-11-03 12:42:02 +08:00
parent 736c096bc0
commit 246dd04279
4 changed files with 21 additions and 12 deletions

View File

@ -167,14 +167,8 @@ AutoHideDockContainerPrivate::AutoHideDockContainerPrivate(
//============================================================================ //============================================================================
CDockContainerWidget* CAutoHideDockContainer::parentContainer() const CDockContainerWidget* CAutoHideDockContainer::parentContainer() const
{ {
if (d->DockArea) // Don't rely on the dock area parent container, when dragging or floating the parent container can change
{ return internal::findParent<CDockContainerWidget*>(this);
return d->DockArea->dockContainer();
}
else
{
return internal::findParent<CDockContainerWidget*>(this);
}
} }
@ -357,7 +351,7 @@ void CAutoHideDockContainer::moveContentsToParent()
//============================================================================ //============================================================================
void CAutoHideDockContainer::cleanupAndDelete() void CAutoHideDockContainer::cleanupAndDelete(bool deleteDockArea)
{ {
const auto dockWidget = d->DockWidget; const auto dockWidget = d->DockWidget;
if (dockWidget) if (dockWidget)
@ -371,6 +365,15 @@ void CAutoHideDockContainer::cleanupAndDelete()
hide(); hide();
deleteLater(); deleteLater();
// Schedule deletion of the dock area after the auto hide widget
// Otherwise, there are issues with the windows native event handler
if (deleteDockArea)
{
d->DockArea->setParent(nullptr);
d->DockArea->deleteLater();
d->DockArea = nullptr;
}
} }

View File

@ -134,8 +134,10 @@ public:
/** /**
* Cleanups up the side tab widget and then deletes itself * Cleanups up the side tab widget and then deletes itself
* deleteDockArea = true is set, this will also delete the dockArea.
* Avoid deleting the dock area floating drag, where the dock area is simply moved into another container
*/ */
void cleanupAndDelete(); void cleanupAndDelete(bool deleteDockArea = true);
/* /*
* Toggles the auto Hide dock container widget * Toggles the auto Hide dock container widget

View File

@ -2073,12 +2073,16 @@ void CDockContainerWidget::registerAutoHideWidget(CAutoHideDockContainer* Autohi
d->AutoHideWidgets.append(AutohideWidget); d->AutoHideWidgets.append(AutohideWidget);
Q_EMIT autoHideWidgetCreated(AutohideWidget); Q_EMIT autoHideWidgetCreated(AutohideWidget);
ADS_PRINT("d->AutoHideWidgets.count() " << d->AutoHideWidgets.count()); ADS_PRINT("d->AutoHideWidgets.count() " << d->AutoHideWidgets.count());
qInfo()<< this << "Size after registering: " << d->AutoHideWidgets.size();
} }
//============================================================================ //============================================================================
void CDockContainerWidget::removeAutoHideWidget(CAutoHideDockContainer* AutohideWidget) void CDockContainerWidget::removeAutoHideWidget(CAutoHideDockContainer* AutohideWidget)
{ {
qInfo() << this << "Auto hide widgets: " << d->AutoHideWidgets;
qInfo() << "Size before removing: " << d->AutoHideWidgets.size();
d->AutoHideWidgets.removeAll(AutohideWidget); d->AutoHideWidgets.removeAll(AutohideWidget);
qInfo() << "Size after removing: " << d->AutoHideWidgets.size();
} }
//============================================================================ //============================================================================

View File

@ -371,11 +371,11 @@ void CFloatingDragPreview::cleanupAutoHideContainerWidget()
auto DroppedArea = qobject_cast<CDockAreaWidget*>(d->Content); auto DroppedArea = qobject_cast<CDockAreaWidget*>(d->Content);
if (DroppedDockWidget && DroppedDockWidget->autoHideDockContainer()) if (DroppedDockWidget && DroppedDockWidget->autoHideDockContainer())
{ {
DroppedDockWidget->autoHideDockContainer()->cleanupAndDelete(); DroppedDockWidget->autoHideDockContainer()->cleanupAndDelete(false);
} }
if (DroppedArea && DroppedArea->autoHideDockContainer()) if (DroppedArea && DroppedArea->autoHideDockContainer())
{ {
DroppedArea->autoHideDockContainer()->cleanupAndDelete(); DroppedArea->autoHideDockContainer()->cleanupAndDelete(false);
} }
} }