clean: deprecations that won't break Qt5 compatibility

This commit is contained in:
shenleban tongying 2024-03-21 20:45:29 -04:00
parent be22cb22b6
commit 48fc8fceff
5 changed files with 17 additions and 18 deletions

View file

@ -65,9 +65,9 @@ void AudioPlayerFactory::reset()
#endif
}
QScopedPointer< ExternalAudioPlayer > externalPlayer( new ExternalAudioPlayer );
std::unique_ptr< ExternalAudioPlayer > externalPlayer( new ExternalAudioPlayer );
setAudioPlaybackProgram( *externalPlayer );
playerPtr.reset( externalPlayer.take() );
playerPtr.reset( externalPlayer.release() );
}
void AudioPlayerFactory::setAudioPlaybackProgram( ExternalAudioPlayer & externalPlayer )

View file

@ -41,7 +41,7 @@ Sources::Sources( QWidget * parent, Config::Class const & cfg ):
// anyone?
QItemEditorCreatorBase * programTypeEditorCreator = new QStandardItemEditorCreator< ProgramTypeEditor >();
itemEditorFactory->registerEditor( QVariant::Int, programTypeEditorCreator );
itemEditorFactory->registerEditor( QMetaType::Int, programTypeEditorCreator );
itemDelegate->setItemEditorFactory( itemEditorFactory.get() );

View file

@ -16,7 +16,7 @@ ExternalAudioPlayer::~ExternalAudioPlayer()
// Set viewer to null first and foremost to make sure that onViewerDestroyed()
// doesn't attempt to start viewer or mess the smart pointer up.
stopAndDestroySynchronously( viewer.take() );
stopAndDestroySynchronously( viewer.release() );
stopAndDestroySynchronously( exitingViewer );
}
@ -56,7 +56,7 @@ void ExternalAudioPlayer::stop()
// 1) the process gets a chance to clean up and save its state;
// 2) there is no event loop blocking and consequently no (short) UI freeze
// while synchronously waiting for the external process to exit.
exitingViewer = viewer.take();
exitingViewer = viewer.release();
}
else // viewer is either not started or already stopped -> simply destroy it.
viewer.reset();
@ -72,14 +72,14 @@ void ExternalAudioPlayer::onViewerDestroyed( QObject * destroyedViewer )
emit error( errorMessage );
}
}
else if ( viewer.data() == destroyedViewer )
viewer.take(); // viewer finished and died -> release ownership.
else if ( viewer.get() == destroyedViewer )
viewer.reset(nullptr); // viewer finished and died -> reset
}
QString ExternalAudioPlayer::startViewer()
{
Q_ASSERT( !exitingViewer && viewer );
connect( viewer.data(), &QObject::destroyed, this, &ExternalAudioPlayer::onViewerDestroyed );
connect( viewer.get(), &QObject::destroyed, this, &ExternalAudioPlayer::onViewerDestroyed );
try {
viewer->start();
}

View file

@ -4,9 +4,8 @@
#ifndef EXTERNALAUDIOPLAYER_HH_INCLUDED
#define EXTERNALAUDIOPLAYER_HH_INCLUDED
#include <QScopedPointer>
#include <QString>
#include "audioplayerinterface.hh"
#include <memory>
class ExternalViewer;
@ -34,16 +33,16 @@ private:
///< the current viewer (if any) is not started yet
///< and waits for exitingViewer to be destroyed first.
struct ScopedPointerDeleteLater
struct QObjectDeleteLater
{
static void cleanup( QObject * p )
{
if ( p )
p->deleteLater();
}
void operator()( QObject * p )
{
if ( p )
p->deleteLater();
}
};
// deleteLater() is safer because viewer actively participates in the QEventLoop.
QScopedPointer< ExternalViewer, ScopedPointerDeleteLater > viewer;
std::unique_ptr< ExternalViewer, QObjectDeleteLater > viewer;
};
#endif // EXTERNALAUDIOPLAYER_HH_INCLUDED

View file

@ -150,7 +150,7 @@ void HeadwordListModel::fetchMore( const QModelIndex & parent )
}
QSet< QString > filtered;
for ( const auto & word : qAsConst( headword ) ) {
for ( const auto & word : std::as_const( headword ) ) {
if ( !containWord( word ) )
filtered.insert( word );
}