magpie/root.cpp

48 lines
1.2 KiB
C++
Raw Normal View History

2023-11-22 23:13:33 +00:00
#include "root.h"
2023-11-24 23:48:01 +00:00
Root::Root(const QUrl& root, int& argc, char* argv[]) :
QGuiApplication(argc, argv),
root(root),
engine(),
context(engine.rootContext()),
api()
2023-11-22 23:13:33 +00:00
{
2023-11-24 23:48:01 +00:00
std::cout << "Starting megpie..." << std::endl;
2023-11-22 23:13:33 +00:00
2023-11-24 23:48:01 +00:00
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);
2023-11-22 23:13:33 +00:00
}
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 << "Squawk is quiting..." << std::endl;
exit(1);
return false;
}
2023-11-24 23:48:01 +00:00
void Root::onObjectCreated(QObject* obj, const QUrl& objUrl) {
if (!obj && objUrl == root)
exit(-2);
}