mirror of
				https://github.com/dolphin-emu/dolphin.git
				synced 2025-10-25 01:19:19 +00:00 
			
		
		
		
	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.
		
			
				
	
	
		
			33 lines
		
	
	
	
		
			669 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
	
		
			669 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| // Copyright 2023 Dolphin Emulator Project
 | |
| // SPDX-License-Identifier: GPL-2.0-or-later
 | |
| 
 | |
| #include "DolphinQt/QtUtils/ClearLayoutRecursively.h"
 | |
| 
 | |
| #include <QLayout>
 | |
| #include <QLayoutItem>
 | |
| #include <QWidget>
 | |
| 
 | |
| void ClearLayoutRecursively(QLayout* layout)
 | |
| {
 | |
|   while (QLayoutItem* child = layout->takeAt(0))
 | |
|   {
 | |
|     if (child == nullptr)
 | |
|       continue;
 | |
| 
 | |
|     if (child->widget())
 | |
|     {
 | |
|       layout->removeWidget(child->widget());
 | |
|       child->widget()->deleteLater();
 | |
|     }
 | |
|     else if (child->layout())
 | |
|     {
 | |
|       ClearLayoutRecursively(child->layout());
 | |
|       layout->removeItem(child);
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       layout->removeItem(child);
 | |
|     }
 | |
|     delete child;
 | |
|   }
 | |
| }
 |