[multimedia/amarok] src: Improve captures in various lambda expressions

Tuomas Nurmi <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 194981adbd85fa3a63b833b98599091df8aa8134 by Tuomas Nurmi.
Committed on 29/07/2026 at 08:59.
Pushed by nurmi into branch 'master'.

Improve captures in various lambda expressions

"implicit capture of ”this” via ”[=]” is deprecated in C++20" so replace with
explicit captures.

M  +1    -1    src/context/applets/albums/plugin/AlbumsEngine.cpp
M  +2    -2    src/context/applets/analyzer/plugin/AnalyzerBase.cpp
M  +1    -1    src/context/applets/wikipedia/plugin/WikipediaEngine.cpp
M  +10   -10   src/covermanager/CoverFetcher.cpp
M  +1    -1    src/covermanager/CoverManager.cpp
M  +2    -2    src/scripting/scriptengine/AmarokBookmarkScript.cpp
M  +2    -2    src/scripting/scriptengine/AmarokCollectionViewScript.cpp
M  +2    -2    src/services/lastfm/LastFmServiceSettings.cpp
M  +1    -1    src/widgets/Osd.cpp

https://invent.kde.org/multimedia/amarok/-/commit/194981adbd85fa3a63b833b98599091df8aa8134

diff --git a/src/context/applets/albums/plugin/AlbumsEngine.cpp b/src/context/applets/albums/plugin/AlbumsEngine.cpp
index 383ba3cbba..fd43f4506b 100644
--- a/src/context/applets/albums/plugin/AlbumsEngine.cpp
+++ b/src/context/applets/albums/plugin/AlbumsEngine.cpp
@@ -146,7 +146,7 @@ void AlbumsEngine::resultReady( const Meta::AlbumList &albums )
     // Include currently playing album in results even when album artist is not current artist
     Meta::AlbumList amended;
     if( m_currentTrack && m_currentTrack->album() && std::find_if( albums.cbegin(), albums.cend(),
-                        [=](auto a) { return *m_currentTrack->album() == *a; } ) == albums.cend() )
+                        [&m_currentTrack = m_currentTrack](auto a) { return *m_currentTrack->album() == *a; } ) == albums.cend() )
     {
         amended.append( albums );
         amended.append( m_currentTrack->album() );
diff --git a/src/context/applets/analyzer/plugin/AnalyzerBase.cpp b/src/context/applets/analyzer/plugin/AnalyzerBase.cpp
index 435d37ae86..dc3928b9b2 100644
--- a/src/context/applets/analyzer/plugin/AnalyzerBase.cpp
+++ b/src/context/applets/analyzer/plugin/AnalyzerBase.cpp
@@ -124,12 +124,12 @@ Analyzer::Base::drawNeedChanged( const bool drawingNeeded )
     if( drawingNeeded )
     {
         connectSignals();
-        QTimer::singleShot( 0, m_worker, [=]() { m_worker->setHibernate( false ); } );
+        QTimer::singleShot( 0, m_worker, [&m_worker = m_worker]() { m_worker->setHibernate( false ); } );
     }
     else
     {
         disconnectSignals();
-        QTimer::singleShot( 0, m_worker, [=]() { m_worker->setHibernate( true ); } );
+        QTimer::singleShot( 0, m_worker, [&m_worker = m_worker]() { m_worker->setHibernate( true ); } );
     }
 }
 
diff --git a/src/context/applets/wikipedia/plugin/WikipediaEngine.cpp b/src/context/applets/wikipedia/plugin/WikipediaEngine.cpp
index 97372e8af1..32a5afb0a8 100644
--- a/src/context/applets/wikipedia/plugin/WikipediaEngine.cpp
+++ b/src/context/applets/wikipedia/plugin/WikipediaEngine.cpp
@@ -57,7 +57,7 @@ WikipediaEngine::WikipediaEngine( QObject* parent )
     connect( The::paletteHandler(), &PaletteHandler::newPalette,
              this, &WikipediaEngine::_paletteChanged );
     connect( The::networkAccessManager(), &NetworkAccessManagerProxy::requestRedirectedUrl,
-             [=](auto url, auto redirurl) { if( urls.contains( url ) ) { urls << redirurl; } } );
+             [&urls = urls](auto url, auto redirurl) { if( urls.contains( url ) ) { urls << redirurl; } } );
 }
 
 WikipediaEngine::~WikipediaEngine()
diff --git a/src/covermanager/CoverFetcher.cpp b/src/covermanager/CoverFetcher.cpp
index 0bb8886051..7c742e340c 100644
--- a/src/covermanager/CoverFetcher.cpp
+++ b/src/covermanager/CoverFetcher.cpp
@@ -98,7 +98,7 @@ CoverFetcher::manualFetch( Meta::AlbumPtr album )
     switch( fetchSource() )
     {
     case CoverFetch::LastFm:
-        QTimer::singleShot( 0, m_queue, [=] () { m_queue->add( album, CoverFetch::Interactive, fetchSource() ); } );
+        QTimer::singleShot( 0, m_queue, [this, album] () { m_queue->add( album, CoverFetch::Interactive, fetchSource() ); } );
         break;
 
     case CoverFetch::Discogs:
@@ -114,7 +114,7 @@ CoverFetcher::manualFetch( Meta::AlbumPtr album )
 void
 CoverFetcher::queueAlbum( Meta::AlbumPtr album )
 {
-    QTimer::singleShot( 0, m_queue, [=] () { m_queue->add( album, CoverFetch::Automatic ); } );
+    QTimer::singleShot( 0, m_queue, [&m_queue = m_queue, album] () { m_queue->add( album, CoverFetch::Automatic ); } );
     debug() << "Queueing automatic cover fetch for:" << album->name();
 }
 
@@ -123,14 +123,14 @@ CoverFetcher::queueAlbums( Meta::AlbumList albums )
 {
     for( Meta::AlbumPtr album : albums )
     {
-        QTimer::singleShot( 0, m_queue, [=] () { m_queue->add( album, CoverFetch::Automatic ); } );
+        QTimer::singleShot( 0, m_queue, [&m_queue = m_queue, album] () { m_queue->add( album, CoverFetch::Automatic ); } );
     }
 }
 
 void
 CoverFetcher::queueQuery( const Meta::AlbumPtr &album, const QString &query, int page )
 {
-    QTimer::singleShot( 0, m_queue, [=] () { m_queue->addQuery( query, fetchSource(), page, album ); } );
+    QTimer::singleShot( 0, m_queue, [this, album, page, query] () { m_queue->addQuery( query, fetchSource(), page, album ); } );
     debug() << QStringLiteral( "Queueing cover fetch query: '%1' (page %2)" ).arg( query, QString::number( page ) );
 }
 
@@ -193,7 +193,7 @@ CoverFetcher::slotResult( const QUrl &url, const QByteArray &data, const Network
     const CoverFetchUnit::Ptr unit( m_urls.take( url ) );
     if( !unit )
     {
-        QTimer::singleShot( 0, m_queue, [=] () { m_queue->remove( unit ); } );
+        QTimer::singleShot( 0, m_queue, [&m_queue = m_queue, unit] () { m_queue->remove( unit ); } );
         return;
     }
 
@@ -207,12 +207,12 @@ CoverFetcher::slotResult( const QUrl &url, const QByteArray &data, const Network
     switch( payload->type() )
     {
     case CoverFetchPayload::Info:
-        QTimer::singleShot( 0, m_queue, [=] () { m_queue->add( unit->album(), unit->options(), payload->source(), data );
+        QTimer::singleShot( 0, m_queue, [&m_queue = m_queue, data, payload, unit] () { m_queue->add( unit->album(), unit->options(), payload->source(), data );
                                                  m_queue->remove( unit ); } );
         break;
 
     case CoverFetchPayload::Search:
-        QTimer::singleShot( 0, m_queue, [=] () { m_queue->add( unit->options(), fetchSource(), data );
+        QTimer::singleShot( 0, m_queue, [this, &m_queue = m_queue, data, unit] () { m_queue->add( unit->options(), fetchSource(), data );
                                                  m_queue->remove( unit ); } );
         break;
 
@@ -264,7 +264,7 @@ CoverFetcher::handleCoverPayload( const CoverFetchUnit::Ptr &unit, const QByteAr
         if( reader.read( &image ) )
         {
             showCover( unit, image, metadata );
-            QTimer::singleShot( 0, m_queue, [=] () {  m_queue->remove( unit ); } );
+            QTimer::singleShot( 0, m_queue, [&m_queue = m_queue, unit] () {  m_queue->remove( unit ); } );
             return;
         }
     }
@@ -387,7 +387,7 @@ CoverFetcher::showCover( const CoverFetchUnit::Ptr &unit,
 void
 CoverFetcher::abortFetch( const CoverFetchUnit::Ptr &unit )
 {
-    QTimer::singleShot( 0, m_queue, [=] () {  m_queue->remove( unit ); } );
+    QTimer::singleShot( 0, m_queue, [&m_queue = m_queue, unit] () {  m_queue->remove( unit ); } );
     m_selectedImages.remove( unit );
     QList<QUrl> urls = m_urls.keys( unit );
     for( const QUrl &url : urls )
@@ -453,7 +453,7 @@ CoverFetcher::finish( const CoverFetchUnit::Ptr &unit,
         break;
     }
 
-    QTimer::singleShot( 0, m_queue, [=] () { m_queue->remove( unit ); } );
+    QTimer::singleShot( 0, m_queue, [&m_queue = m_queue, unit] () { m_queue->remove( unit ); } );
 
     Q_EMIT finishedSingle( static_cast< int >( state ) );
 }
diff --git a/src/covermanager/CoverManager.cpp b/src/covermanager/CoverManager.cpp
index 0b75e15ebf..6a988ca837 100644
--- a/src/covermanager/CoverManager.cpp
+++ b/src/covermanager/CoverManager.cpp
@@ -707,7 +707,7 @@ CoverManager::updateStatusBar()
         m_fetchButton->setEnabled( missingCounter );
     }
 
-    QTimer::singleShot( 0, this, [=]() { setStatusText( text ); } );
+    QTimer::singleShot( 0, this, [this, text]() { setStatusText( text ); } );
 }
 
 void
diff --git a/src/scripting/scriptengine/AmarokBookmarkScript.cpp b/src/scripting/scriptengine/AmarokBookmarkScript.cpp
index 8e4c99c5d3..efc0e4028d 100644
--- a/src/scripting/scriptengine/AmarokBookmarkScript.cpp
+++ b/src/scripting/scriptengine/AmarokBookmarkScript.cpp
@@ -46,7 +46,7 @@ AmarokBookmarkScript::AmarokBookmarkScript( QJSEngine *engine )
     m_engine->globalObject().setProperty( QStringLiteral("Bookmark"), bookmarkCtor );
 
     qRegisterMetaType<BookmarkGroupList>();
-    QMetaType::registerConverter<BookmarkGroupList, QJSValue>( [=] (BookmarkGroupList bgList) { return toScriptArray<BookmarkGroupList>( m_engine, bgList ); } );
+    QMetaType::registerConverter<BookmarkGroupList, QJSValue>( [&m_engine = m_engine] (BookmarkGroupList bgList) { return toScriptArray<BookmarkGroupList>( m_engine, bgList ); } );
     QMetaType::registerConverter<QJSValue, BookmarkGroupList>( [] (QJSValue jsValue) {
         BookmarkGroupList bgList;
         fromScriptArray<BookmarkGroupList>( jsValue, bgList );
@@ -54,7 +54,7 @@ AmarokBookmarkScript::AmarokBookmarkScript( QJSEngine *engine )
     } );
 
     qRegisterMetaType<BookmarkList>();
-    QMetaType::registerConverter<BookmarkList,QJSValue>( [=] (BookmarkList bList) { return toScriptArray<BookmarkList>( m_engine, bList); } );
+    QMetaType::registerConverter<BookmarkList,QJSValue>( [&m_engine = m_engine] (BookmarkList bList) { return toScriptArray<BookmarkList>( m_engine, bList); } );
     QMetaType::registerConverter<QJSValue,BookmarkList>( [] (QJSValue jsValue) {
         BookmarkList bList;
         fromScriptArray<BookmarkList>( jsValue, bList );
diff --git a/src/scripting/scriptengine/AmarokCollectionViewScript.cpp b/src/scripting/scriptengine/AmarokCollectionViewScript.cpp
index 63573c746b..2066f88e93 100644
--- a/src/scripting/scriptengine/AmarokCollectionViewScript.cpp
+++ b/src/scripting/scriptengine/AmarokCollectionViewScript.cpp
@@ -62,8 +62,8 @@ AmarokCollectionViewScript::AmarokCollectionViewScript( AmarokScriptEngine *engi
     scriptObject.setProperty( QStringLiteral("Category"), engine->enumObject( m_categoryEnum ) );
 
     qRegisterMetaType<CollectionTreeItem*>();
-    QMetaType::registerConverter<CollectionTreeItem*, QJSValue>( [=] (CollectionTreeItem* item) { return CollectionViewItem::toScriptValue( m_engine, item ); } );
-    QMetaType::registerConverter<QJSValue, CollectionTreeItem*>( [=] (QJSValue jsValue) {
+    QMetaType::registerConverter<CollectionTreeItem*, QJSValue>( [&m_engine = m_engine] (CollectionTreeItem* item) { return CollectionViewItem::toScriptValue( m_engine, item ); } );
+    QMetaType::registerConverter<QJSValue, CollectionTreeItem*>( [] (QJSValue jsValue) {
         CollectionTreeItem* item;
         fromScriptValue<CollectionTreeItem*, CollectionViewItem>( jsValue, item );
         return item;
diff --git a/src/services/lastfm/LastFmServiceSettings.cpp b/src/services/lastfm/LastFmServiceSettings.cpp
index b8906c5d91..c4c8dd73af 100644
--- a/src/services/lastfm/LastFmServiceSettings.cpp
+++ b/src/services/lastfm/LastFmServiceSettings.cpp
@@ -154,10 +154,10 @@ LastFmServiceSettings::onAuthTokenReady()
     if( QDesktopServices::openUrl( QUrl( QStringLiteral( "https://www.last.fm/api/auth/?api_key=%1&token=%2" )
         .arg( QLatin1String( Amarok::lastfmApiKey() ), lfm[ QStringLiteral("token") ].text() ) ) ) )
     {
-        QTimer::singleShot( 2000, [=] () // wait a moment for the browser to open, as connecting won't succeed before interaction in browser
+        QTimer::singleShot( 2000, [this, lfm] () // wait a moment for the browser to open, as connecting won't succeed before interaction in browser
         {
             disconnect( m_configDialog->connectToAccount, &QPushButton::clicked, this, &LastFmServiceSettings::initiateTokenAuth );
-            connect( m_configDialog->connectToAccount, &QPushButton::clicked, [=]() { this->getSessionToken( lfm[ QStringLiteral("token") ].text() ); } );
+            connect( m_configDialog->connectToAccount, &QPushButton::clicked, [this, lfm]() { this->getSessionToken( lfm[ QStringLiteral("token") ].text() ); } );
             m_configDialog->connectToAccount->setEnabled( true );
             m_configDialog->connectToAccount->setText( i18nc( "Pushbutton to complete Last.fm authentication process",
                                                               "Finish connecting account" ) );
diff --git a/src/widgets/Osd.cpp b/src/widgets/Osd.cpp
index 6b123eeb15..24702df384 100644
--- a/src/widgets/Osd.cpp
+++ b/src/widgets/Osd.cpp
@@ -406,7 +406,7 @@ OSDWidget::paintEvent( QPaintEvent *e )
     // Only show position if the track didn't just start playing
     if( pos > m_duration + 500 )
     {
-        QTimer::singleShot( 1000, this, [=] () { update(); });
+        QTimer::singleShot( 1000, this, [this] () { update(); });
         osdtext.replace( QStringLiteral("%{\033A%}"), QString(Meta::msToPrettyTime( pos ) + QLatin1Char('/') ) );
     }
     else
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.