123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include <QGuiApplication>
- #include <QObject>
- #include <QQmlApplicationEngine>
- #include <QQmlComponent>
- #include <QQmlContext>
- #include <csignal>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <iostream>
- #include <sys/prctl.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include "qmlhandler.h"
- using namespace std;
- int inpipefd[2];
- int outpipefd[2];
- char buf[1024];
- int main(int argc, char *argv[]) {
- qInfo() << "Program Start";
- pid_t pid = 0;
- char msg[256];
- int status;
- pipe(inpipefd);
- pipe(outpipefd);
- pid = fork();
- if (pid == 0) {
- // Child
- dup2(outpipefd[0], STDIN_FILENO);
- dup2(inpipefd[1], STDOUT_FILENO);
- dup2(inpipefd[1], STDERR_FILENO);
- // ask kernel to deliver SIGTERM in case the parent dies
- prctl(PR_SET_PDEATHSIG, SIGTERM);
- // Set the path to the CLI - pass argument h (help) for now
- // TODO: Change hardcoded path
- execl("../../cli/build/ccats-cli", "ccats-cli", "127.0.0.1", "--machine",
- (char *)NULL);
- exit(1);
- }
- close(outpipefd[0]);
- close(inpipefd[1]);
- // ########## Load GUI ##########
- QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- // This has to be here to fix warnings
- QCoreApplication::setOrganizationName("CCats");
- QGuiApplication app(argc, argv);
- QQmlApplicationEngine engine;
- QMLHandler qmlHandler;
- engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
- QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
- QObject *object = component.create();
- return app.exec();
- }
|