Use QObject->deleteLater() instead of the delete operator to destroy child widgets of the layout. This prevents crashes caused by pending events trying to access the now-destroyed widget.