added main app class

This commit is contained in:
adamsjensen 2018-03-02 13:34:10 +03:00
parent f02e1a0e8e
commit 8b72ff8ef3
4 changed files with 64 additions and 9 deletions

View File

@ -27,7 +27,8 @@ SOURCES += main.cpp \
../sync/song.cpp \
../sync/sync.cpp \
../sync/Log.cpp\
../sync/exaptions.cpp
../sync/exaptions.cpp \
app.cpp
RESOURCES += qml.qrc
@ -57,5 +58,6 @@ HEADERS += \
../sync/player.h \
../sync/song.h \
../sync/sync.h \
../sync/Log.h
../sync/Log.h \
app.h

26
SoundBand/app.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "app.h"
#include <QQmlApplicationEngine>
#include "syncengine.h"
App::App(QObject* ptr):
QObject(ptr)
{
qmlEngine = new QQmlApplicationEngine();
syncEngine = new SyncEngine();
}
bool App::run(){
qmlRegisterType<SyncEngine>("SyncEngine",1,0,"SyncEngine");
qmlEngine->load(QUrl(QStringLiteral("qrc:/main.qml")));
if (qmlEngine->rootObjects().isEmpty())
return false;
return true;
}
App::~App(){
delete syncEngine;
delete qmlEngine;
}

30
SoundBand/app.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef APP_H
#define APP_H
#include <QObject>
#include "syncengine.h"
class SyncEngine;
class QQmlApplicationEngine;
/**
* @brief The App class
* general application object
*/
class App : public QObject
{
private:
SyncEngine *syncEngine;
QQmlApplicationEngine *qmlEngine;
public:
explicit App(QObject *ptr = nullptr);
/**
* @brief run app
* @return false if app not running, true if all done
*/
bool run();
~App();
};
#endif // APP_H

View File

@ -1,6 +1,6 @@
#include <QApplication>
#include <QQmlApplicationEngine>
#include "syncengine.h"
#include "app.h"
int main(int argc, char *argv[])
{
@ -9,12 +9,9 @@ int main(int argc, char *argv[])
#endif
QApplication app(argc, argv);
QQmlApplicationEngine engine;
qmlRegisterType<SyncEngine>("SyncEngine",1,0,"SyncEngine");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
App soundBand;
if(!soundBand.run())
return -1;
return app.exec();
}