]> Some of my projects - aniplayer.git/commitdiff
Only create the player when starting the instance
authorAPTX <marek321@gmail.com>
Sun, 26 Feb 2017 14:44:18 +0000 (15:44 +0100)
committerAPTX <marek321@gmail.com>
Sun, 26 Feb 2017 14:44:18 +0000 (15:44 +0100)
core/instancemanager.cpp
core/instancemanager.h

index a36c9e05aaab66bc915e3624c0945a1ba4784563..e59bee21e7d1f9d62f017fcceff3f5966c3c958a 100644 (file)
@@ -5,6 +5,7 @@
 #include <QQmlApplicationEngine>
 #include <QQmlContext>
 
+#include "player.h"
 #include "timeformatter.h"
 
 Q_LOGGING_CATEGORY(imCategory, "InstanceManager")
@@ -25,11 +26,14 @@ int InstanceManager::runInstance(const QCoreApplication &app) {
 
   QQmlApplicationEngine engine;
 
+  player = new Player{this};
+  Q_CHECK_PTR(player);
+
   if (!positionalArgs.empty())
-    player.setNextSource(QUrl::fromUserInput(positionalArgs[0]));
+    player->setNextSource(QUrl::fromUserInput(positionalArgs[0]));
   qCDebug(imCategory, "Player Created");
   TimeFormatter timeFormatter;
-  engine.rootContext()->setContextProperty("player", &player);
+  engine.rootContext()->setContextProperty("player", player);
   engine.rootContext()->setContextProperty("timeFormatter", &timeFormatter);
   qCDebug(imCategory, "Player Added");
   engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
@@ -60,6 +64,6 @@ void InstanceManager::handleSingleInstanceMessage(const QString &message) {
     qCInfo(imCategory()) << "No new file to open";
     return;
   }
-
-  player.loadAndPlay(QUrl::fromUserInput(positionalArgs[0]));
+  Q_ASSERT(player);
+  player->loadAndPlay(QUrl::fromUserInput(positionalArgs[0]));
 }
index e3371391370a3c1912f13f75cd59737caec3b911..0b8f17ed28d0a919fa69304e92305a397d351bd8 100644 (file)
@@ -7,7 +7,7 @@
 #include <QCommandLineOption>
 #include <QCommandLineParser>
 
-#include "player.h"
+class Player;
 
 class InstanceManager : public QObject {
   Q_OBJECT
@@ -26,7 +26,7 @@ private:
                                           "Start playback specific position",
                                           "position in seconds", "0"};
   QCommandLineParser parser;
-  Player player;
+  Player *player;
 };
 
 #endif // INSTANCEMANAGER_H