summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorVaL Doroshchuk <valentyn.doroshchuk@qt.io>2017-09-14 09:56:30 +0200
committerVaL Doroshchuk <valentyn.doroshchuk@qt.io>2017-09-28 14:00:26 +0000
commit62d72daf70fed1d7fa1c38bd52468b6536ec6cad (patch)
tree867428c277ac8cc0fcfa5c15003d6ad5b43f03cd /examples
parent61b0771e832cad41c726995aafd7bea705909bdd (diff)
Modernize the Player example
Fixed memory leak. Renamed members, avoided passing args by copy. Changed the style of member initialization. Changed 0 to nullptr. Changed to new signal/slot style if possible. Removed Q_WS_SIMULATOR ifdef. Changed signal/slot connection style. Task-number: QTBUG-60627 Change-Id: I85bd6e56fe87f4e17f3c9964d6d1fdcb8202c519 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/multimediawidgets/player/histogramwidget.cpp37
-rw-r--r--examples/multimediawidgets/player/histogramwidget.h16
-rw-r--r--examples/multimediawidgets/player/main.cpp7
-rw-r--r--examples/multimediawidgets/player/player.cpp282
-rw-r--r--examples/multimediawidgets/player/player.h48
-rw-r--r--examples/multimediawidgets/player/playercontrols.cpp119
-rw-r--r--examples/multimediawidgets/player/playercontrols.h20
-rw-r--r--examples/multimediawidgets/player/playlistmodel.cpp29
-rw-r--r--examples/multimediawidgets/player/playlistmodel.h6
-rw-r--r--examples/multimediawidgets/player/videowidget.h2
10 files changed, 272 insertions, 294 deletions
diff --git a/examples/multimediawidgets/player/histogramwidget.cpp b/examples/multimediawidgets/player/histogramwidget.cpp
index 71c243e23..c4019b5f8 100644
--- a/examples/multimediawidgets/player/histogramwidget.cpp
+++ b/examples/multimediawidgets/player/histogramwidget.cpp
@@ -49,7 +49,7 @@ class QAudioLevel : public QWidget
{
Q_OBJECT
public:
- explicit QAudioLevel(QWidget *parent = 0);
+ explicit QAudioLevel(QWidget *parent = nullptr);
// Using [0; 1.0] range
void setLevel(qreal level);
@@ -58,12 +58,11 @@ protected:
void paintEvent(QPaintEvent *event);
private:
- qreal m_level;
+ qreal m_level = 0;
};
QAudioLevel::QAudioLevel(QWidget *parent)
- : QWidget(parent)
- , m_level(0.0)
+ : QWidget(parent)
{
setMinimumHeight(15);
setMaximumHeight(50);
@@ -91,12 +90,10 @@ void QAudioLevel::paintEvent(QPaintEvent *event)
HistogramWidget::HistogramWidget(QWidget *parent)
: QWidget(parent)
- , m_levels(128)
- , m_isBusy(false)
{
m_processor.moveToThread(&m_processorThread);
- qRegisterMetaType<QVector<qreal> >("QVector<qreal>");
- connect(&m_processor, SIGNAL(histogramReady(QVector<qreal>)), SLOT(setHistogram(QVector<qreal>)));
+ qRegisterMetaType<QVector<qreal>>("QVector<qreal>");
+ connect(&m_processor, &FrameProcessor::histogramReady, this, &HistogramWidget::setHistogram);
m_processorThread.start(QThread::LowestPriority);
setLayout(new QHBoxLayout);
}
@@ -107,7 +104,7 @@ HistogramWidget::~HistogramWidget()
m_processorThread.wait(10000);
}
-void HistogramWidget::processFrame(QVideoFrame frame)
+void HistogramWidget::processFrame(const QVideoFrame &frame)
{
if (m_isBusy && frame.isValid())
return; //drop frame
@@ -226,24 +223,24 @@ QVector<qreal> getBufferLevels(const T *buffer, int frames, int channels)
return max_values;
}
-void HistogramWidget::processBuffer(QAudioBuffer buffer)
+void HistogramWidget::processBuffer(const QAudioBuffer &buffer)
{
- if (audioLevels.count() != buffer.format().channelCount()) {
- qDeleteAll(audioLevels);
- audioLevels.clear();
+ if (m_audioLevels.count() != buffer.format().channelCount()) {
+ qDeleteAll(m_audioLevels);
+ m_audioLevels.clear();
for (int i = 0; i < buffer.format().channelCount(); ++i) {
QAudioLevel *level = new QAudioLevel(this);
- audioLevels.append(level);
+ m_audioLevels.append(level);
layout()->addWidget(level);
}
}
QVector<qreal> levels = getBufferLevels(buffer);
for (int i = 0; i < levels.count(); ++i)
- audioLevels.at(i)->setLevel(levels.at(i));
+ m_audioLevels.at(i)->setLevel(levels.at(i));
}
-void HistogramWidget::setHistogram(QVector<qreal> histogram)
+void HistogramWidget::setHistogram(const QVector<qreal> &histogram)
{
m_isBusy = false;
m_histogram = histogram;
@@ -254,7 +251,7 @@ void HistogramWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
- if (!audioLevels.isEmpty())
+ if (!m_audioLevels.isEmpty())
return;
QPainter painter(this);
@@ -266,7 +263,7 @@ void HistogramWidget::paintEvent(QPaintEvent *event)
qreal barWidth = width() / (qreal)m_histogram.size();
- for (int i = 0; i < m_histogram.size(); i++) {
+ for (int i = 0; i < m_histogram.size(); ++i) {
qreal h = m_histogram[i] * height();
// draw level
painter.fillRect(barWidth * i, height() - h, barWidth * (i + 1), height(), Qt::red);
@@ -290,7 +287,7 @@ void FrameProcessor::processFrame(QVideoFrame frame, int levels)
frame.pixelFormat() == QVideoFrame::Format_NV12) {
// Process YUV data
uchar *b = frame.bits();
- for (int y = 0; y < frame.height(); y++) {
+ for (int y = 0; y < frame.height(); ++y) {
uchar *lastPixel = b + frame.width();
for (uchar *curPixel = b; curPixel < lastPixel; curPixel++)
histogram[(*curPixel * levels) >> 8] += 1.0;
@@ -304,7 +301,7 @@ void FrameProcessor::processFrame(QVideoFrame frame, int levels)
image = image.convertToFormat(QImage::Format_RGB32);
const QRgb* b = (const QRgb*)image.bits();
- for (int y = 0; y < image.height(); y++) {
+ for (int y = 0; y < image.height(); ++y) {
const QRgb *lastPixel = b + frame.width();
for (const QRgb *curPixel = b; curPixel < lastPixel; curPixel++)
histogram[(qGray(*curPixel) * levels) >> 8] += 1.0;
diff --git a/examples/multimediawidgets/player/histogramwidget.h b/examples/multimediawidgets/player/histogramwidget.h
index a85dd27e1..b55ab265f 100644
--- a/examples/multimediawidgets/player/histogramwidget.h
+++ b/examples/multimediawidgets/player/histogramwidget.h
@@ -56,7 +56,7 @@ public slots:
void processFrame(QVideoFrame frame, int levels);
signals:
- void histogramReady(QVector<qreal> histogram);
+ void histogramReady(const QVector<qreal> &histogram);
};
class HistogramWidget : public QWidget
@@ -64,25 +64,25 @@ class HistogramWidget : public QWidget
Q_OBJECT
public:
- explicit HistogramWidget(QWidget *parent = 0);
+ explicit HistogramWidget(QWidget *parent = nullptr);
~HistogramWidget();
void setLevels(int levels) { m_levels = levels; }
public slots:
- void processFrame(QVideoFrame frame);
- void processBuffer(QAudioBuffer buffer);
- void setHistogram(QVector<qreal> histogram);
+ void processFrame(const QVideoFrame &frame);
+ void processBuffer(const QAudioBuffer &buffer);
+ void setHistogram(const QVector<qreal> &histogram);
protected:
void paintEvent(QPaintEvent *event) override;
private:
QVector<qreal> m_histogram;
- int m_levels;
+ int m_levels = 128;
FrameProcessor m_processor;
QThread m_processorThread;
- bool m_isBusy;
- QVector<QAudioLevel *> audioLevels;
+ bool m_isBusy = false;
+ QVector<QAudioLevel *> m_audioLevels;
};
#endif // HISTOGRAMWIDGET_H
diff --git a/examples/multimediawidgets/player/main.cpp b/examples/multimediawidgets/player/main.cpp
index a3dabe15d..af8013502 100644
--- a/examples/multimediawidgets/player/main.cpp
+++ b/examples/multimediawidgets/player/main.cpp
@@ -63,16 +63,11 @@ int main(int argc, char *argv[])
if (!parser.positionalArguments().isEmpty() && player.isPlayerAvailable()) {
QList<QUrl> urls;
- foreach (const QString &a, parser.positionalArguments())
+ for (auto &a: parser.positionalArguments())
urls.append(QUrl::fromUserInput(a, QDir::currentPath(), QUrl::AssumeLocalFile));
player.addToPlaylist(urls);
}
-#if defined(Q_WS_SIMULATOR)
- player.setAttribute(Qt::WA_LockLandscapeOrientation);
- player.showMaximized();
-#else
player.show();
-#endif
return app.exec();
}
diff --git a/examples/multimediawidgets/player/player.cpp b/examples/multimediawidgets/player/player.cpp
index 085dff6a7..ce178d4a1 100644
--- a/examples/multimediawidgets/player/player.cpp
+++ b/examples/multimediawidgets/player/player.cpp
@@ -43,6 +43,7 @@
#include "playercontrols.h"
#include "playlistmodel.h"
#include "histogramwidget.h"
+#include "videowidget.h"
#include <QMediaService>
#include <QMediaPlaylist>
@@ -53,105 +54,98 @@
Player::Player(QWidget *parent)
: QWidget(parent)
- , videoWidget(0)
- , coverLabel(0)
- , slider(0)
- , colorDialog(0)
{
//! [create-objs]
- player = new QMediaPlayer(this);
- player->setAudioRole(QAudio::VideoRole);
+ m_player = new QMediaPlayer(this);
+ m_player->setAudioRole(QAudio::VideoRole);
qInfo() << "Supported audio roles:";
- for (QAudio::Role role : player->supportedAudioRoles())
+ for (QAudio::Role role : m_player->supportedAudioRoles())
qInfo() << " " << role;
// owned by PlaylistModel
- playlist = new QMediaPlaylist();
- player->setPlaylist(playlist);
+ m_playlist = new QMediaPlaylist();
+ m_player->setPlaylist(m_playlist);
//! [create-objs]
- connect(player, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64)));
- connect(player, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64)));
- connect(player, SIGNAL(metaDataChanged()), SLOT(metaDataChanged()));
- connect(playlist, SIGNAL(currentIndexChanged(int)), SLOT(playlistPositionChanged(int)));
- connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
- this, SLOT(statusChanged(QMediaPlayer::MediaStatus)));
- connect(player, SIGNAL(bufferStatusChanged(int)), this, SLOT(bufferingProgress(int)));
- connect(player, SIGNAL(videoAvailableChanged(bool)), this, SLOT(videoAvailableChanged(bool)));
- connect(player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(displayErrorMessage()));
- connect(player, &QMediaPlayer::stateChanged, this, &Player::stateChanged);
+ connect(m_player, &QMediaPlayer::durationChanged, this, &Player::durationChanged);
+ connect(m_player, &QMediaPlayer::positionChanged, this, &Player::positionChanged);
+ connect(m_player, QOverload<>::of(&QMediaPlayer::metaDataChanged), this, &Player::metaDataChanged);
+ connect(m_playlist, &QMediaPlaylist::currentIndexChanged, this, &Player::playlistPositionChanged);
+ connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &Player::statusChanged);
+ connect(m_player, &QMediaPlayer::bufferStatusChanged, this, &Player::bufferingProgress);
+ connect(m_player, &QMediaPlayer::videoAvailableChanged, this, &Player::videoAvailableChanged);
+ connect(m_player, QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error), this, &Player::displayErrorMessage);
+ connect(m_player, &QMediaPlayer::stateChanged, this, &Player::stateChanged);
//! [2]
- videoWidget = new VideoWidget(this);
- player->setVideoOutput(videoWidget);
+ m_videoWidget = new VideoWidget(this);
+ m_player->setVideoOutput(m_videoWidget);
- playlistModel = new PlaylistModel(this);
- playlistModel->setPlaylist(playlist);
+ m_playlistModel = new PlaylistModel(this);
+ m_playlistModel->setPlaylist(m_playlist);
//! [2]
- playlistView = new QListView(this);
- playlistView->setModel(playlistModel);
- playlistView->setCurrentIndex(playlistModel->index(playlist->currentIndex(), 0));
+ m_playlistView = new QListView(this);
+ m_playlistView->setModel(m_playlistModel);
+ m_playlistView->setCurrentIndex(m_playlistModel->index(m_playlist->currentIndex(), 0));
- connect(playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(jump(QModelIndex)));
+ connect(m_playlistView, &QAbstractItemView::activated, this, &Player::jump);
- slider = new QSlider(Qt::Horizontal, this);
- slider->setRange(0, player->duration() / 1000);
+ m_slider = new QSlider(Qt::Horizontal, this);
+ m_slider->setRange(0, m_player->duration() / 1000);
- labelDuration = new QLabel(this);
- connect(slider, SIGNAL(sliderMoved(int)), this, SLOT(seek(int)));
+ m_labelDuration = new QLabel(this);
+ connect(m_slider, &QSlider::sliderMoved, this, &Player::seek);
- labelHistogram = new QLabel(this);
- labelHistogram->setText("Histogram:");
- videoHistogram = new HistogramWidget(this);
- audioHistogram = new HistogramWidget(this);
+ m_labelHistogram = new QLabel(this);
+ m_labelHistogram->setText("Histogram:");
+ m_videoHistogram = new HistogramWidget(this);
+ m_audioHistogram = new HistogramWidget(this);
QHBoxLayout *histogramLayout = new QHBoxLayout;
- histogramLayout->addWidget(labelHistogram);
- histogramLayout->addWidget(videoHistogram, 1);
- histogramLayout->addWidget(audioHistogram, 2);
+ histogramLayout->addWidget(m_labelHistogram);
+ histogramLayout->addWidget(m_videoHistogram, 1);
+ histogramLayout->addWidget(m_audioHistogram, 2);
- videoProbe = new QVideoProbe(this);
- connect(videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), videoHistogram, SLOT(processFrame(QVideoFrame)));
- videoProbe->setSource(player);
+ m_videoProbe = new QVideoProbe(this);
+ connect(m_videoProbe, &QVideoProbe::videoFrameProbed, m_videoHistogram, &HistogramWidget::processFrame);
+ m_videoProbe->setSource(m_player);
- audioProbe = new QAudioProbe(this);
- connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)), audioHistogram, SLOT(processBuffer(QAudioBuffer)));
- audioProbe->setSource(player);
+ m_audioProbe = new QAudioProbe(this);
+ connect(m_audioProbe, &QAudioProbe::audioBufferProbed, m_audioHistogram, &HistogramWidget::processBuffer);
+ m_audioProbe->setSource(m_player);
QPushButton *openButton = new QPushButton(tr("Open"), this);
- connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
+ connect(openButton, &QPushButton::clicked, this, &Player::open);
PlayerControls *controls = new PlayerControls(this);
- controls->setState(player->state());
- controls->setVolume(player->volume());
+ controls->setState(m_player->state());
+ controls->setVolume(m_player->volume());
controls->setMuted(controls->isMuted());
- connect(controls, SIGNAL(play()), player, SLOT(play()));
- connect(controls, SIGNAL(pause()), player, SLOT(pause()));
- connect(controls, SIGNAL(stop()), player, SLOT(stop()));
- connect(controls, SIGNAL(next()), playlist, SLOT(next()));
- connect(controls, SIGNAL(previous()), this, SLOT(previousClicked()));
- connect(controls, SIGNAL(changeVolume(int)), player, SLOT(setVolume(int)));
- connect(controls, SIGNAL(changeMuting(bool)), player, SLOT(setMuted(bool)));
- connect(controls, SIGNAL(changeRate(qreal)), player, SLOT(setPlaybackRate(qreal)));
+ connect(controls, &PlayerControls::play, m_player, &QMediaPlayer::play);
+ connect(controls, &PlayerControls::pause, m_player, &QMediaPlayer::pause);
+ connect(controls, &PlayerControls::stop, m_player, &QMediaPlayer::stop);
+ connect(controls, &PlayerControls::next, m_playlist, &QMediaPlaylist::next);
+ connect(controls, &PlayerControls::previous, this, &Player::previousClicked);
+ connect(controls, &PlayerControls::changeVolume, m_player, &QMediaPlayer::setVolume);
+ connect(controls, &PlayerControls::changeMuting, m_player, &QMediaPlayer::setMuted);
+ connect(controls, &PlayerControls::changeRate, m_player, &QMediaPlayer::setPlaybackRate);
+ connect(controls, &PlayerControls::stop, m_videoWidget, QOverload<>::of(&QVideoWidget::update));
- connect(controls, SIGNAL(stop()), videoWidget, SLOT(update()));
+ connect(m_player, &QMediaPlayer::stateChanged, controls, &PlayerControls::setState);
+ connect(m_player, &QMediaPlayer::volumeChanged, controls, &PlayerControls::setVolume);
+ connect(m_player, &QMediaPlayer::mutedChanged, controls, &PlayerControls::setMuted);
- connect(player, SIGNAL(stateChanged(QMediaPlayer::State)),
- controls, SLOT(setState(QMediaPlayer::State)));
- connect(player, SIGNAL(volumeChanged(int)), controls, SLOT(setVolume(int)));
- connect(player, SIGNAL(mutedChanged(bool)), controls, SLOT(setMuted(bool)));
+ m_fullScreenButton = new QPushButton(tr("FullScreen"), this);
+ m_fullScreenButton->setCheckable(true);
- fullScreenButton = new QPushButton(tr("FullScreen"), this);
- fullScreenButton->setCheckable(true);
-
- colorButton = new QPushButton(tr("Color Options..."), this);
- colorButton->setEnabled(false);
- connect(colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
+ m_colorButton = new QPushButton(tr("Color Options..."), this);
+ m_colorButton->setEnabled(false);
+ connect(m_colorButton, &QPushButton::clicked, this, &Player::showColorDialog);
QBoxLayout *displayLayout = new QHBoxLayout;
- displayLayout->addWidget(videoWidget, 2);
- displayLayout->addWidget(playlistView);
+ displayLayout->addWidget(m_videoWidget, 2);
+ displayLayout->addWidget(m_playlistView);
QBoxLayout *controlLayout = new QHBoxLayout;
controlLayout->setMargin(0);
@@ -159,14 +153,14 @@ Player::Player(QWidget *parent)
controlLayout->addStretch(1);
controlLayout->addWidget(controls);
controlLayout->addStretch(1);
- controlLayout->addWidget(fullScreenButton);
- controlLayout->addWidget(colorButton);
+ controlLayout->addWidget(m_fullScreenButton);
+ controlLayout->addWidget(m_colorButton);
QBoxLayout *layout = new QVBoxLayout;
layout->addLayout(displayLayout);
QHBoxLayout *hLayout = new QHBoxLayout;
- hLayout->addWidget(slider);
- hLayout->addWidget(labelDuration);
+ hLayout->addWidget(m_slider);
+ hLayout->addWidget(m_labelDuration);
layout->addLayout(hLayout);
layout->addLayout(controlLayout);
layout->addLayout(histogramLayout);
@@ -179,10 +173,10 @@ Player::Player(QWidget *parent)
"Please check the media service plugins are installed."));
controls->setEnabled(false);
- playlistView->setEnabled(false);
+ m_playlistView->setEnabled(false);
openButton->setEnabled(false);
- colorButton->setEnabled(false);
- fullScreenButton->setEnabled(false);
+ m_colorButton->setEnabled(false);
+ m_fullScreenButton->setEnabled(false);
}
metaDataChanged();
@@ -194,7 +188,7 @@ Player::~Player()
bool Player::isPlayerAvailable() const
{
- return player->isAvailable();
+ return m_player->isAvailable();
}
void Player::open()
@@ -202,7 +196,7 @@ void Player::open()
QFileDialog fileDialog(this);
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setWindowTitle(tr("Open Files"));
- QStringList supportedMimeTypes = player->supportedMimeTypes();
+ QStringList supportedMimeTypes = m_player->supportedMimeTypes();
if (!supportedMimeTypes.isEmpty()) {
supportedMimeTypes.append("audio/x-m3u"); // MP3 playlists
fileDialog.setMimeTypeFilters(supportedMimeTypes);
@@ -220,41 +214,41 @@ static bool isPlaylist(const QUrl &url) // Check for ".m3u" playlists.
return fileInfo.exists() && !fileInfo.suffix().compare(QLatin1String("m3u"), Qt::CaseInsensitive);
}
-void Player::addToPlaylist(const QList<QUrl> urls)
+void Player::addToPlaylist(const QList<QUrl> &urls)
{
- foreach (const QUrl &url, urls) {
+ for (auto &url: urls) {
if (isPlaylist(url))
- playlist->load(url);
+ m_playlist->load(url);
else
- playlist->addMedia(url);
+ m_playlist->addMedia(url);
}
}
void Player::durationChanged(qint64 duration)
{
- this->duration = duration/1000;
- slider->setMaximum(duration / 1000);
+ m_duration = duration / 1000;
+ m_slider->setMaximum(m_duration);
}
void Player::positionChanged(qint64 progress)
{
- if (!slider->isSliderDown()) {
- slider->setValue(progress / 1000);
- }
+ if (!m_slider->isSliderDown())
+ m_slider->setValue(progress / 1000);
+
updateDurationInfo(progress / 1000);
}
void Player::metaDataChanged()
{
- if (player->isMetaDataAvailable()) {
+ if (m_player->isMetaDataAvailable()) {
setTrackInfo(QString("%1 - %2")
- .arg(player->metaData(QMediaMetaData::AlbumArtist).toString())
- .arg(player->metaData(QMediaMetaData::Title).toString()));
+ .arg(m_player->metaData(QMediaMetaData::AlbumArtist).toString())
+ .arg(m_player->metaData(QMediaMetaData::Title).toString()));
- if (coverLabel) {
- QUrl url = player->metaData(QMediaMetaData::CoverArtUrlLarge).value<QUrl>();
+ if (m_coverLabel) {
+ QUrl url = m_player->metaData(QMediaMetaData::CoverArtUrlLarge).value<QUrl>();
- coverLabel->setPixmap(!url.isEmpty()
+ m_coverLabel->setPixmap(!url.isEmpty()
? QPixmap(url.toString())
: QPixmap());
}
@@ -265,29 +259,29 @@ void Player::previousClicked()
{
// Go to previous track if we are within the first 5 seconds of playback
// Otherwise, seek to the beginning.
- if(player->position() <= 5000)
- playlist->previous();
+ if (m_player->position() <= 5000)
+ m_playlist->previous();
else
- player->setPosition(0);
+ m_player->setPosition(0);
}
void Player::jump(const QModelIndex &index)
{
if (index.isValid()) {
- playlist->setCurrentIndex(index.row());
- player->play();
+ m_playlist->setCurrentIndex(index.row());
+ m_player->play();
}
}
void Player::playlistPositionChanged(int currentItem)
{
clearHistogram();
- playlistView->setCurrentIndex(playlistModel->index(currentItem, 0));
+ m_playlistView->setCurrentIndex(m_playlistModel->index(currentItem, 0));
}
void Player::seek(int seconds)
{
- player->setPosition(seconds * 1000);
+ m_player->setPosition(seconds * 1000);
}
void Player::statusChanged(QMediaPlayer::MediaStatus status)
@@ -344,86 +338,84 @@ void Player::bufferingProgress(int progress)
void Player::videoAvailableChanged(bool available)
{
if (!available) {
- disconnect(fullScreenButton, SIGNAL(clicked(bool)),
- videoWidget, SLOT(setFullScreen(bool)));
- disconnect(videoWidget, SIGNAL(fullScreenChanged(bool)),
- fullScreenButton, SLOT(setChecked(bool)));
- videoWidget->setFullScreen(false);
+ disconnect(m_fullScreenButton, &QPushButton::clicked, m_videoWidget, &QVideoWidget::setFullScreen);
+ disconnect(m_videoWidget, &QVideoWidget::fullScreenChanged, m_fullScreenButton, &QPushButton::setChecked);
+ m_videoWidget->setFullScreen(false);
} else {
- connect(fullScreenButton, SIGNAL(clicked(bool)),
- videoWidget, SLOT(setFullScreen(bool)));
- connect(videoWidget, SIGNAL(fullScreenChanged(bool)),
- fullScreenButton, SLOT(setChecked(bool)));
+ connect(m_fullScreenButton, &QPushButton::clicked, m_videoWidget, &QVideoWidget::setFullScreen);
+ connect(m_videoWidget, &QVideoWidget::fullScreenChanged, m_fullScreenButton, &QPushButton::setChecked);
- if (fullScreenButton->isChecked())
- videoWidget->setFullScreen(true);
+ if (m_fullScreenButton->isChecked())
+ m_videoWidget->setFullScreen(true);
}
- colorButton->setEnabled(available);
+ m_colorButton->setEnabled(available);
}
void Player::setTrackInfo(const QString &info)
{
- trackInfo = info;
- if (!statusInfo.isEmpty())
- setWindowTitle(QString("%1 | %2").arg(trackInfo).arg(statusInfo));
+ m_trackInfo = info;
+ if (!m_statusInfo.isEmpty())
+ setWindowTitle(QString("%1 | %2").arg(m_trackInfo).arg(m_statusInfo));
else
- setWindowTitle(trackInfo);
+ setWindowTitle(m_trackInfo);
}
void Player::setStatusInfo(const QString &info)
{
- statusInfo = info;
- if (!statusInfo.isEmpty())
- setWindowTitle(QString("%1 | %2").arg(trackInfo).arg(statusInfo));
+ m_statusInfo = info;
+ if (!m_statusInfo.isEmpty())
+ setWindowTitle(QString("%1 | %2").arg(m_trackInfo).arg(m_statusInfo));
else
- setWindowTitle(trackInfo);
+ setWindowTitle(m_trackInfo);
}
void Player::displayErrorMessage()
{
- setStatusInfo(player->errorString());
+ setStatusInfo(m_player->errorString());
}
void Player::updateDurationInfo(qint64 currentInfo)
{
QString tStr;
- if (currentInfo || duration) {
- QTime currentTime((currentInfo/3600)%60, (currentInfo/60)%60, currentInfo%60, (currentInfo*1000)%1000);
- QTime totalTime((duration/3600)%60, (duration/60)%60, duration%60, (duration*1000)%1000);
+ if (currentInfo || m_duration) {
+ QTime currentTime((currentInfo / 3600) % 60, (currentInfo / 60) % 60,
+ currentInfo % 60, (currentInfo * 1000) % 1000);
+ QTime totalTime((m_duration / 3600) % 60, (m_duration / 60) % 60,
+ m_duration % 60, (m_duration * 1000) % 1000);
QString format = "mm:ss";
- if (duration > 3600)
+ if (m_duration > 3600)
format = "hh:mm:ss";
tStr = currentTime.toString(format) + " / " + totalTime.toString(format);
}
- labelDuration->setText(tStr);
+ m_labelDuration->setText(tStr);
}
void Player::showColorDialog()
{
- if (!colorDialog) {
+ if (!m_colorDialog) {
QSlider *brightnessSlider = new QSlider(Qt::Horizontal);
brightnessSlider->setRange(-100, 100);
- brightnessSlider->setValue(videoWidget->brightness());
- connect(brightnessSlider, SIGNAL(sliderMoved(int)), videoWidget, SLOT(setBrightness(int)));
- connect(videoWidget, SIGNAL(brightnessChanged(int)), brightnessSlider, SLOT(setValue(int)));
+ brightnessSlider->setValue(m_videoWidget->brightness());
+ connect(brightnessSlider, &QSlider::sliderMoved, m_videoWidget, &QVideoWidget::setBrightness);
+ connect(m_videoWidget, &QVideoWidget::brightnessChanged, brightnessSlider, &QSlider::setValue);
QSlider *contrastSlider = new QSlider(Qt::Horizontal);
contrastSlider->setRange(-100, 100);
- contrastSlider->setValue(videoWidget->contrast());
- connect(contrastSlider, SIGNAL(sliderMoved(int)), videoWidget, SLOT(setContrast(int)));
- connect(videoWidget, SIGNAL(contrastChanged(int)), contrastSlider, SLOT(setValue(int)));
+ contrastSlider->setValue(m_videoWidget->contrast());
+ connect(contrastSlider, &QSlider::sliderMoved, m_videoWidget, &QVideoWidget::setContrast);
+ connect(m_videoWidget, &QVideoWidget::contrastChanged, contrastSlider, &QSlider::setValue);
QSlider *hueSlider = new QSlider(Qt::Horizontal);
hueSlider->setRange(-100, 100);
- hueSlider->setValue(videoWidget->hue());
- connect(hueSlider, SIGNAL(sliderMoved(int)), videoWidget, SLOT(setHue(int)));
- connect(videoWidget, SIGNAL(hueChanged(int)), hueSlider, SLOT(setValue(int)));
+ hueSlider->setValue(m_videoWidget->hue());
+ connect(hueSlider, &QSlider::sliderMoved, m_videoWidget, &QVideoWidget::setHue);
+ connect(m_videoWidget, &QVideoWidget::hueChanged, hueSlider, &QSlider::setValue);
QSlider *saturationSlider = new QSlider(Qt::Horizontal);
saturationSlider->setRange(-100, 100);
- saturationSlider->setValue(videoWidget->saturation());
- connect(saturationSlider, SIGNAL(sliderMoved(int)), videoWidget, SLOT(setSaturation(int)));
- connect(videoWidget, SIGNAL(saturationChanged(int)), saturationSlider, SLOT(setValue(int)));
+ saturationSlider->setValue(m_videoWidget->saturation());
+ connect(saturationSlider, &QSlider::sliderMoved, m_videoWidget, &QVideoWidget::setSaturation);
+ connect(m_videoWidget, &QVideoWidget::saturationChanged, saturationSlider, &QSlider::setValue);
QFormLayout *layout = new QFormLayout;
layout->addRow(tr("Brightness"), brightnessSlider);
@@ -434,17 +426,17 @@ void Player::showColorDialog()
QPushButton *button = new QPushButton(tr("Close"));
layout->addRow(button);
- colorDialog = new QDialog(this);
- colorDialog->setWindowTitle(tr("Color Options"));
- colorDialog->setLayout(layout);
+ m_colorDialog = new QDialog(this);
+ m_colorDialog->setWindowTitle(tr("Color Options"));
+ m_colorDialog->setLayout(layout);
- connect(button, SIGNAL(clicked()), colorDialog, SLOT(close()));
+ connect(button, &QPushButton::clicked, m_colorDialog, &QDialog::close);
}
- colorDialog->show();
+ m_colorDialog->show();
}
void Player::clearHistogram()
{
- QMetaObject::invokeMethod(videoHistogram, "processFrame", Qt::QueuedConnection, Q_ARG(QVideoFrame, QVideoFrame()));
- QMetaObject::invokeMethod(audioHistogram, "processBuffer", Qt::QueuedConnection, Q_ARG(QAudioBuffer, QAudioBuffer()));
+ QMetaObject::invokeMethod(m_videoHistogram, "processFrame", Qt::QueuedConnection, Q_ARG(QVideoFrame, QVideoFrame()));
+ QMetaObject::invokeMethod(m_audioHistogram, "processBuffer", Qt::QueuedConnection, Q_ARG(QAudioBuffer, QAudioBuffer()));
}
diff --git a/examples/multimediawidgets/player/player.h b/examples/multimediawidgets/player/player.h
index ff60f8c63..66be3f747 100644
--- a/examples/multimediawidgets/player/player.h
+++ b/examples/multimediawidgets/player/player.h
@@ -41,8 +41,6 @@
#ifndef PLAYER_H
#define PLAYER_H
-#include "videowidget.h"
-
#include <QWidget>
#include <QMediaPlayer>
#include <QMediaPlaylist>
@@ -67,12 +65,12 @@ class Player : public QWidget
Q_OBJECT
public:
- Player(QWidget *parent = 0);
+ explicit Player(QWidget *parent = nullptr);
~Player();
bool isPlayerAvailable() const;
- void addToPlaylist(const QList<QUrl> urls);
+ void addToPlaylist(const QList<QUrl> &urls);
signals:
void fullScreenChanged(bool fullScreen);
@@ -105,27 +103,27 @@ private:
void handleCursor(QMediaPlayer::MediaStatus status);
void updateDurationInfo(qint64 currentInfo);
- QMediaPlayer *player;
- QMediaPlaylist *playlist;
- VideoWidget *videoWidget;
- QLabel *coverLabel;
- QSlider *slider;
- QLabel *labelDuration;
- QPushButton *fullScreenButton;
- QPushButton *colorButton;
- QDialog *colorDialog;
-
- QLabel *labelHistogram;
- HistogramWidget *videoHistogram;
- HistogramWidget *audioHistogram;
- QVideoProbe *videoProbe;
- QAudioProbe *audioProbe;
-
- PlaylistModel *playlistModel;
- QAbstractItemView *playlistView;
- QString trackInfo;
- QString statusInfo;
- qint64 duration;
+ QMediaPlayer *m_player = nullptr;
+ QMediaPlaylist *m_playlist = nullptr;
+ QVideoWidget *m_videoWidget = nullptr;
+ QLabel *m_coverLabel = nullptr;
+ QSlider *m_slider = nullptr;
+ QLabel *m_labelDuration = nullptr;
+ QPushButton *m_fullScreenButton = nullptr;
+ QPushButton *m_colorButton = nullptr;
+ QDialog *m_colorDialog = nullptr;
+
+ QLabel *m_labelHistogram = nullptr;
+ HistogramWidget *m_videoHistogram = nullptr;
+ HistogramWidget *m_audioHistogram = nullptr;
+ QVideoProbe *m_videoProbe = nullptr;
+ QAudioProbe *m_audioProbe = nullptr;
+
+ PlaylistModel *m_playlistModel = nullptr;
+ QAbstractItemView *m_playlistView = nullptr;
+ QString m_trackInfo;
+ QString m_statusInfo;
+ qint64 m_duration;
};
#endif // PLAYER_H
diff --git a/examples/multimediawidgets/player/playercontrols.cpp b/examples/multimediawidgets/player/playercontrols.cpp
index 3d968b452..daeec924c 100644
--- a/examples/multimediawidgets/player/playercontrols.cpp
+++ b/examples/multimediawidgets/player/playercontrols.cpp
@@ -49,89 +49,80 @@
PlayerControls::PlayerControls(QWidget *parent)
: QWidget(parent)
- , playerState(QMediaPlayer::StoppedState)
- , playerMuted(false)
- , playButton(0)
- , stopButton(0)
- , nextButton(0)
- , previousButton(0)
- , muteButton(0)
- , volumeSlider(0)
- , rateBox(0)
{
- playButton = new QToolButton(this);
- playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
+ m_playButton = new QToolButton(this);
+ m_playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
- connect(playButton, SIGNAL(clicked()), this, SLOT(playClicked()));
+ connect(m_playButton, &QAbstractButton::clicked, this, &PlayerControls::playClicked);
- stopButton = new QToolButton(this);
- stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
- stopButton->setEnabled(false);
+ m_stopButton = new QToolButton(this);
+ m_stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
+ m_stopButton->setEnabled(false);
- connect(stopButton, SIGNAL(clicked()), this, SIGNAL(stop()));
+ connect(m_stopButton, &QAbstractButton::clicked, this, &PlayerControls::stop);
- nextButton = new QToolButton(this);
- nextButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipForward));
+ m_nextButton = new QToolButton(this);
+ m_nextButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipForward));
- connect(nextButton, SIGNAL(clicked()), this, SIGNAL(next()));
+ connect(m_nextButton, &QAbstractButton::clicked, this, &PlayerControls::next);
- previousButton = new QToolButton(this);
- previousButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward));
+ m_previousButton = new QToolButton(this);
+ m_previousButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward));
- connect(previousButton, SIGNAL(clicked()), this, SIGNAL(previous()));
+ connect(m_previousButton, &QAbstractButton::clicked, this, &PlayerControls::previous);
- muteButton = new QToolButton(this);
- muteButton->setIcon(style()->standardIcon(QStyle::SP_MediaVolume));
+ m_muteButton = new QToolButton(this);
+ m_muteButton->setIcon(style()->standardIcon(QStyle::SP_MediaVolume));
- connect(muteButton, SIGNAL(clicked()), this, SLOT(muteClicked()));
+ connect(m_muteButton, &QAbstractButton::clicked, this, &PlayerControls::muteClicked);
- volumeSlider = new QSlider(Qt::Horizontal, this);
- volumeSlider->setRange(0, 100);
+ m_volumeSlider = new QSlider(Qt::Horizontal, this);
+ m_volumeSlider->setRange(0, 100);
- connect(volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(onVolumeSliderValueChanged()));
+ connect(m_volumeSlider, &QSlider::valueChanged, this, &PlayerControls::onVolumeSliderValueChanged);
- rateBox = new QComboBox(this);
- rateBox->addItem("0.5x", QVariant(0.5));
- rateBox->addItem("1.0x", QVariant(1.0));
- rateBox->addItem("2.0x", QVariant(2.0));
- rateBox->setCurrentIndex(1);
+ m_rateBox = new QComboBox(this);
+ m_rateBox->addItem("0.5x", QVariant(0.5));
+ m_rateBox->addItem("1.0x", QVariant(1.0));
+ m_rateBox->addItem("2.0x", QVariant(2.0));
+ m_rateBox->setCurrentIndex(1);
- connect(rateBox, SIGNAL(activated(int)), SLOT(updateRate()));
+ connect(m_rateBox, QOverload<int>::of(&QComboBox::activated), this, &PlayerControls::updateRate);
QBoxLayout *layout = new QHBoxLayout;
layout->setMargin(0);
- layout->addWidget(stopButton);
- layout->addWidget(previousButton);
- layout->addWidget(playButton);
- layout->addWidget(nextButton);
- layout->addWidget(muteButton);
- layout->addWidget(volumeSlider);
- layout->addWidget(rateBox);
+ layout->addWidget(m_stopButton);
+ layout->addWidget(m_previousButton);
+ layout->addWidget(m_playButton);
+ layout->addWidget(m_nextButton);
+ layout->addWidget(m_muteButton);
+ layout->addWidget(m_volumeSlider);
+ layout->addWidget(m_rateBox);
setLayout(layout);
}
QMediaPlayer::State PlayerControls::state() const
{
- return playerState;
+ return m_playerState;
}
void PlayerControls::setState(QMediaPlayer::State state)
{
- if (state != playerState) {
- playerState = state;
+ if (state != m_playerState) {
+ m_playerState = state;
switch (state) {
case QMediaPlayer::StoppedState:
- stopButton->setEnabled(false);
- playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
+ m_stopButton->setEnabled(false);
+ m_playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
break;
case QMediaPlayer::PlayingState:
- stopButton->setEnabled(true);
- playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
+ m_stopButton->setEnabled(true);
+ m_playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
break;
case QMediaPlayer::PausedState:
- stopButton->setEnabled(true);
- playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
+ m_stopButton->setEnabled(true);
+ m_playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
break;
}
}
@@ -139,7 +130,7 @@ void PlayerControls::setState(QMediaPlayer::State state)
int PlayerControls::volume() const
{
- qreal linearVolume = QAudio::convertVolume(volumeSlider->value() / qreal(100),
+ qreal linearVolume = QAudio::convertVolume(m_volumeSlider->value() / qreal(100),
QAudio::LogarithmicVolumeScale,
QAudio::LinearVolumeScale);
@@ -152,20 +143,20 @@ void PlayerControls::setVolume(int volume)
QAudio::LinearVolumeScale,
QAudio::LogarithmicVolumeScale);
- volumeSlider->setValue(qRound(logarithmicVolume * 100));
+ m_volumeSlider->setValue(qRound(logarithmicVolume * 100));
}
bool PlayerControls::isMuted() const
{
- return playerMuted;
+ return m_playerMuted;
}
void PlayerControls::setMuted(bool muted)
{
- if (muted != playerMuted) {
- playerMuted = muted;
+ if (muted != m_playerMuted) {
+ m_playerMuted = muted;
- muteButton->setIcon(style()->standardIcon(muted
+ m_muteButton->setIcon(style()->standardIcon(muted
? QStyle::SP_MediaVolumeMuted
: QStyle::SP_MediaVolume));
}
@@ -173,7 +164,7 @@ void PlayerControls::setMuted(bool muted)
void PlayerControls::playClicked()
{
- switch (playerState) {
+ switch (m_playerState) {
case QMediaPlayer::StoppedState:
case QMediaPlayer::PausedState:
emit play();
@@ -186,25 +177,25 @@ void PlayerControls::playClicked()
void PlayerControls::muteClicked()
{
- emit changeMuting(!playerMuted);
+ emit changeMuting(!m_playerMuted);
}
qreal PlayerControls::playbackRate() const
{
- return rateBox->itemData(rateBox->currentIndex()).toDouble();
+ return m_rateBox->itemData(m_rateBox->currentIndex()).toDouble();
}
void PlayerControls::setPlaybackRate(float rate)
{
- for (int i = 0; i < rateBox->count(); ++i) {
- if (qFuzzyCompare(rate, float(rateBox->itemData(i).toDouble()))) {
- rateBox->setCurrentIndex(i);
+ for (int i = 0; i < m_rateBox->count(); ++i) {
+ if (qFuzzyCompare(rate, float(m_rateBox->itemData(i).toDouble()))) {
+ m_rateBox->setCurrentIndex(i);
return;
}
}
- rateBox->addItem(QString("%1x").arg(rate), QVariant(rate));
- rateBox->setCurrentIndex(rateBox->count() - 1);
+ m_rateBox->addItem(QString("%1x").arg(rate), QVariant(rate));
+ m_rateBox->setCurrentIndex(m_rateBox->count() - 1);
}
void PlayerControls::updateRate()
diff --git a/examples/multimediawidgets/player/playercontrols.h b/examples/multimediawidgets/player/playercontrols.h
index d29a06d6c..d44ae6c4a 100644
--- a/examples/multimediawidgets/player/playercontrols.h
+++ b/examples/multimediawidgets/player/playercontrols.h
@@ -55,7 +55,7 @@ class PlayerControls : public QWidget
Q_OBJECT
public:
- PlayerControls(QWidget *parent = 0);
+ explicit PlayerControls(QWidget *parent = nullptr);
QMediaPlayer::State state() const;
int volume() const;
@@ -85,15 +85,15 @@ private slots:
void onVolumeSliderValueChanged();
private:
- QMediaPlayer::State playerState;
- bool playerMuted;
- QAbstractButton *playButton;
- QAbstractButton *stopButton;
- QAbstractButton *nextButton;
- QAbstractButton *previousButton;
- QAbstractButton *muteButton;
- QAbstractSlider *volumeSlider;
- QComboBox *rateBox;
+ QMediaPlayer::State m_playerState = QMediaPlayer::StoppedState;
+ bool m_playerMuted = false;
+ QAbstractButton *m_playButton = nullptr;
+ QAbstractButton *m_stopButton = nullptr;
+ QAbstractButton *m_nextButton = nullptr;
+ QAbstractButton *m_previousButton = nullptr;
+ QAbstractButton *m_muteButton = nullptr;
+ QAbstractSlider *m_volumeSlider = nullptr;
+ QComboBox *m_rateBox = nullptr;
};
#endif // PLAYERCONTROLS_H
diff --git a/examples/multimediawidgets/player/playlistmodel.cpp b/examples/multimediawidgets/player/playlistmodel.cpp
index 18748c819..bd913d5d0 100644
--- a/examples/multimediawidgets/player/playlistmodel.cpp
+++ b/examples/multimediawidgets/player/playlistmodel.cpp
@@ -46,7 +46,10 @@
PlaylistModel::PlaylistModel(QObject *parent)
: QAbstractItemModel(parent)
- , m_playlist(0)
+{
+}
+
+PlaylistModel::~PlaylistModel()
{
}
@@ -92,28 +95,28 @@ QVariant PlaylistModel::data(const QModelIndex &index, int role) const
QMediaPlaylist *PlaylistModel::playlist() const
{
- return m_playlist;
+ return m_playlist.data();
}
void PlaylistModel::setPlaylist(QMediaPlaylist *playlist)
{
if (m_playlist) {
- disconnect(m_playlist, SIGNAL(mediaAboutToBeInserted(int,int)), this, SLOT(beginInsertItems(int,int)));
- disconnect(m_playlist, SIGNAL(mediaInserted(int,int)), this, SLOT(endInsertItems()));
- disconnect(m_playlist, SIGNAL(mediaAboutToBeRemoved(int,int)), this, SLOT(beginRemoveItems(int,int)));
- disconnect(m_playlist, SIGNAL(mediaRemoved(int,int)), this, SLOT(endRemoveItems()));
- disconnect(m_playlist, SIGNAL(mediaChanged(int,int)), this, SLOT(changeItems(int,int)));
+ disconnect(m_playlist.data(), &QMediaPlaylist::mediaAboutToBeInserted, this, &PlaylistModel::beginInsertItems);
+ disconnect(m_playlist.data(), &QMediaPlaylist::mediaInserted, this, &PlaylistModel::endInsertItems);
+ disconnect(m_playlist.data(), &QMediaPlaylist::mediaAboutToBeRemoved, this, &PlaylistModel::beginRemoveItems);
+ disconnect(m_playlist.data(), &QMediaPlaylist::mediaRemoved, this, &PlaylistModel::endRemoveItems);
+ disconnect(m_playlist.data(), &QMediaPlaylist::mediaChanged, this, &PlaylistModel::changeItems);
}
beginResetModel();
- m_playlist = playlist;
+ m_playlist.reset(playlist);
if (m_playlist) {
- connect(m_playlist, SIGNAL(mediaAboutToBeInserted(int,int)), this, SLOT(beginInsertItems(int,int)));
- connect(m_playlist, SIGNAL(mediaInserted(int,int)), this, SLOT(endInsertItems()));
- connect(m_playlist, SIGNAL(mediaAboutToBeRemoved(int,int)), this, SLOT(beginRemoveItems(int,int)));
- connect(m_playlist, SIGNAL(mediaRemoved(int,int)), this, SLOT(endRemoveItems()));
- connect(m_playlist, SIGNAL(mediaChanged(int,int)), this, SLOT(changeItems(int,int)));
+ connect(m_playlist.data(), &QMediaPlaylist::mediaAboutToBeInserted, this, &PlaylistModel::beginInsertItems);
+ connect(m_playlist.data(), &QMediaPlaylist::mediaInserted, this, &PlaylistModel::endInsertItems);
+ connect(m_playlist.data(), &QMediaPlaylist::mediaAboutToBeRemoved, this, &PlaylistModel::beginRemoveItems);
+ connect(m_playlist.data(), &QMediaPlaylist::mediaRemoved, this, &PlaylistModel::endRemoveItems);
+ connect(m_playlist.data(), &QMediaPlaylist::mediaChanged, this, &PlaylistModel::changeItems);
}
endResetModel();
diff --git a/examples/multimediawidgets/player/playlistmodel.h b/examples/multimediawidgets/player/playlistmodel.h
index 960943f1c..827312d9f 100644
--- a/examples/multimediawidgets/player/playlistmodel.h
+++ b/examples/multimediawidgets/player/playlistmodel.h
@@ -42,6 +42,7 @@
#define PLAYLISTMODEL_H
#include <QAbstractItemModel>
+#include <QScopedPointer>
QT_BEGIN_NAMESPACE
class QMediaPlaylist;
@@ -58,7 +59,8 @@ public:
ColumnCount
};
- PlaylistModel(QObject *parent = 0);
+ explicit PlaylistModel(QObject *parent = nullptr);
+ ~PlaylistModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
@@ -81,7 +83,7 @@ private slots:
void changeItems(int start, int end);
private:
- QMediaPlaylist *m_playlist;
+ QScopedPointer<QMediaPlaylist> m_playlist;
QMap<QModelIndex, QVariant> m_data;
};
diff --git a/examples/multimediawidgets/player/videowidget.h b/examples/multimediawidgets/player/videowidget.h
index 00a27a78b..e88d01441 100644
--- a/examples/multimediawidgets/player/videowidget.h
+++ b/examples/multimediawidgets/player/videowidget.h
@@ -48,7 +48,7 @@ class VideoWidget : public QVideoWidget
Q_OBJECT
public:
- VideoWidget(QWidget *parent = 0);
+ explicit VideoWidget(QWidget *parent = nullptr);
protected:
void keyPressEvent(QKeyEvent *event) override;