From 9ad7034db4f00a0a9cc586d49b89152501f5f611 Mon Sep 17 00:00:00 2001 From: APTX Date: Mon, 27 Feb 2017 01:11:50 +0100 Subject: [PATCH] Proper solution to Player QML registration --- core/player.cpp | 10 ++++------ core/player.h | 4 +--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/core/player.cpp b/core/player.cpp index 0be95be..56c5509 100644 --- a/core/player.cpp +++ b/core/player.cpp @@ -7,11 +7,7 @@ Q_LOGGING_CATEGORY(playerCategory, "Player") Player::Player(BackendPluginBase *backendPlugin, QObject *parent) : QObject(parent) { - if (!backendPlugin) { - qCCritical(playerCategory) - << "Trying to create a player without a backendPlugin"; - return; - } + Q_ASSERT(backendPlugin); qCDebug(playerCategory) << "Creating player" << this; m_backend = backendPlugin->createInstance(this); Q_CHECK_PTR(m_backend); @@ -204,7 +200,9 @@ void Player::reqisterQmlTypes() { qRegisterMetaType("TimeStamp"); qRegisterMetaType("StreamIndex"); qRegisterMetaType("Volume"); - qmlRegisterType("org.aptx.aniplayer", 1, 0, "Player"); + qmlRegisterUncreatableType( + "org.aptx.aniplayer", 1, 0, "Player", + "The player is provided to QML as the 'player' global variable."); } bool Player::canLoadVideoNow() const { diff --git a/core/player.h b/core/player.h index c96d582..e199fc1 100644 --- a/core/player.h +++ b/core/player.h @@ -52,9 +52,7 @@ public: static const constexpr Volume MAX_VOLUME = Volume{1.0}; - // BackendPluginBase * allowed to be null because this is exposed to QML - // for the enums/types. Player should never be created in QML. - explicit Player(BackendPluginBase * = nullptr, QObject *parent = nullptr); + explicit Player(BackendPluginBase *, QObject *parent = nullptr); ~Player() override; enum class PlayState { -- 2.52.0