mirror of
https://github.com/LMMS/lmms.git
synced 2026-04-01 21:04:18 -04:00
Replace every use of the foreach macro with a C++11 range-based for loop
This prevents a race condition with Qt5. A foreach loop makes a copy of its Qt container, increasing the reference count to the container's internal data. Qt5 often asserts isDetached(), which requires the reference count to be <= 1. This assertion fails when the foreach loop increases the reference count at exactly the wrong moment. Using a range-based for loop prevents an unnecessary copy from being made and ensures this race condition isn't triggered.
This commit is contained in:
@@ -145,7 +145,7 @@ MainWindow::MainWindow() :
|
||||
|
||||
#if ! defined(LMMS_BUILD_APPLE)
|
||||
QFileInfoList drives = QDir::drives();
|
||||
foreach( const QFileInfo & drive, drives )
|
||||
for( const QFileInfo & drive : drives )
|
||||
{
|
||||
root_paths += drive.absolutePath();
|
||||
}
|
||||
@@ -602,7 +602,7 @@ void MainWindow::finalize()
|
||||
gui->songEditor()->parentWidget()->show();
|
||||
|
||||
// reset window title every time we change the state of a subwindow to show the correct title
|
||||
foreach( QMdiSubWindow * subWindow, workspace()->subWindowList() )
|
||||
for( const QMdiSubWindow * subWindow : workspace()->subWindowList() )
|
||||
{
|
||||
connect( subWindow, SIGNAL( windowStateChanged(Qt::WindowStates,Qt::WindowStates) ), this, SLOT( resetWindowTitle() ) );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user