summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorSze Howe Koh <szehowe.koh@gmail.com>2012-12-19 00:11:29 +0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-19 11:07:34 +0100
commit404b7dbe3fce3881990fc5a1bd908c72750f6ad9 (patch)
treed21605c10697518fceb2b8bf56d92139013eeef2 /examples
parentd13a7a1f8949c4fab37783064cfba27a49757608 (diff)
Example: Notify user of errors
Before, the widget simply failed silently, which gave the impression that the widget is broken. Change-Id: I8ab7ed0e0a62f9643791b6f4732f7f3b2cd7521a Reviewed-by: Martin Smith <martin.smith@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/multimediawidgets/videowidget/videoplayer.cpp15
-rw-r--r--examples/multimediawidgets/videowidget/videoplayer.h3
2 files changed, 17 insertions, 1 deletions
diff --git a/examples/multimediawidgets/videowidget/videoplayer.cpp b/examples/multimediawidgets/videowidget/videoplayer.cpp
index d961a63ff..4083543e5 100644
--- a/examples/multimediawidgets/videowidget/videoplayer.cpp
+++ b/examples/multimediawidgets/videowidget/videoplayer.cpp
@@ -49,6 +49,7 @@ VideoPlayer::VideoPlayer(QWidget *parent)
, mediaPlayer(0, QMediaPlayer::VideoSurface)
, playButton(0)
, positionSlider(0)
+ , errorLabel(0)
{
QVideoWidget *videoWidget = new QVideoWidget;
@@ -68,6 +69,9 @@ VideoPlayer::VideoPlayer(QWidget *parent)
connect(positionSlider, SIGNAL(sliderMoved(int)),
this, SLOT(setPosition(int)));
+ errorLabel = new QLabel;
+ errorLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+
QBoxLayout *controlLayout = new QHBoxLayout;
controlLayout->setMargin(0);
controlLayout->addWidget(openButton);
@@ -77,6 +81,7 @@ VideoPlayer::VideoPlayer(QWidget *parent)
QBoxLayout *layout = new QVBoxLayout;
layout->addWidget(videoWidget);
layout->addLayout(controlLayout);
+ layout->addWidget(errorLabel);
setLayout(layout);
@@ -85,6 +90,7 @@ VideoPlayer::VideoPlayer(QWidget *parent)
this, SLOT(mediaStateChanged(QMediaPlayer::State)));
connect(&mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
connect(&mediaPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(durationChanged(qint64)));
+ connect(&mediaPlayer, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(handleError()));
}
VideoPlayer::~VideoPlayer()
@@ -93,11 +99,12 @@ VideoPlayer::~VideoPlayer()
void VideoPlayer::openFile()
{
+ errorLabel->setText("");
+
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),QDir::homePath());
if (!fileName.isEmpty()) {
mediaPlayer.setMedia(QUrl::fromLocalFile(fileName));
-
playButton->setEnabled(true);
}
}
@@ -140,3 +147,9 @@ void VideoPlayer::setPosition(int position)
{
mediaPlayer.setPosition(position);
}
+
+void VideoPlayer::handleError()
+{
+ playButton->setEnabled(false);
+ errorLabel->setText("Error: " + mediaPlayer.errorString());
+}
diff --git a/examples/multimediawidgets/videowidget/videoplayer.h b/examples/multimediawidgets/videowidget/videoplayer.h
index ddad18724..0bd720bfc 100644
--- a/examples/multimediawidgets/videowidget/videoplayer.h
+++ b/examples/multimediawidgets/videowidget/videoplayer.h
@@ -49,6 +49,7 @@
QT_BEGIN_NAMESPACE
class QAbstractButton;
class QSlider;
+class QLabel;
QT_END_NAMESPACE
class VideoPlayer : public QWidget
@@ -67,11 +68,13 @@ private slots:
void positionChanged(qint64 position);
void durationChanged(qint64 duration);
void setPosition(int position);
+ void handleError();
private:
QMediaPlayer mediaPlayer;
QAbstractButton *playButton;
QSlider *positionSlider;
+ QLabel *errorLabel;
};
#endif