]> Some of my projects - aniplayer.git/commitdiff
Proper solution to Player QML registration
authorAPTX <marek321@gmail.com>
Mon, 27 Feb 2017 00:11:50 +0000 (01:11 +0100)
committerAPTX <marek321@gmail.com>
Mon, 27 Feb 2017 00:11:50 +0000 (01:11 +0100)
core/player.cpp
core/player.h

index 0be95be021734f79bb5fd169eb2b3b16a183ded3..56c55092e13a3be719bbb5e606f1cbf55778b8ec 100644 (file)
@@ -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>("TimeStamp");
   qRegisterMetaType<StreamIndex>("StreamIndex");
   qRegisterMetaType<Volume>("Volume");
-  qmlRegisterType<Player>("org.aptx.aniplayer", 1, 0, "Player");
+  qmlRegisterUncreatableType<Player>(
+      "org.aptx.aniplayer", 1, 0, "Player",
+      "The player is provided to QML as the 'player' global variable.");
 }
 
 bool Player::canLoadVideoNow() const {
index c96d582900993cde87b322cb1922b2e69c0621c3..e199fc1d06073d4eccae47f33fea6f56dbcdbbd6 100644 (file)
@@ -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 {