48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include "root.h"
|
|
|
|
Root::Root(const QUrl& root, int& argc, char* argv[]) :
|
|
QGuiApplication(argc, argv),
|
|
root(root),
|
|
engine(),
|
|
context(engine.rootContext()),
|
|
api()
|
|
{
|
|
std::cout << "Starting Magpie..." << std::endl;
|
|
|
|
connect(&engine, &QQmlApplicationEngine::objectCreated,
|
|
this, &Root::onObjectCreated,
|
|
Qt::QueuedConnection
|
|
);
|
|
|
|
engine.load(root);
|
|
if (engine.rootObjects().isEmpty())
|
|
throw std::runtime_error("Couldn't looad root qml object");
|
|
|
|
context->setContextProperty("API", &api);
|
|
}
|
|
|
|
Root::~Root() {
|
|
|
|
}
|
|
|
|
bool Root::notify(QObject* receiver, QEvent* e) {
|
|
try {
|
|
return QGuiApplication::notify(receiver, e);
|
|
} catch (const std::exception& e) {
|
|
std::cout << "Caught an exception, error message:\n" << e.what() << std::endl;
|
|
} catch (const int& e) {
|
|
std::cout << "Caught int exception: " << e << std::endl;
|
|
} catch (...) {
|
|
std::cout << "Caught an exception" << std::endl;
|
|
}
|
|
|
|
std::cout << "Magpie is quiting..." << std::endl;
|
|
exit(1);
|
|
return false;
|
|
}
|
|
|
|
void Root::onObjectCreated(QObject* obj, const QUrl& objUrl) {
|
|
if (!obj && objUrl == root)
|
|
exit(-2);
|
|
}
|