From: APTX Date: Sun, 26 Feb 2017 14:44:18 +0000 (+0100) Subject: Only create the player when starting the instance X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=f4d8922cdd1a8930a3099ca5bfbe74b08af0f472;p=aniplayer.git Only create the player when starting the instance --- diff --git a/core/instancemanager.cpp b/core/instancemanager.cpp index a36c9e0..e59bee2 100644 --- a/core/instancemanager.cpp +++ b/core/instancemanager.cpp @@ -5,6 +5,7 @@ #include #include +#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])); } diff --git a/core/instancemanager.h b/core/instancemanager.h index e337139..0b8f17e 100644 --- a/core/instancemanager.h +++ b/core/instancemanager.h @@ -7,7 +7,7 @@ #include #include -#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