main.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <QGuiApplication>
  2. #include <QObject>
  3. #include <QQmlApplicationEngine>
  4. #include <QQmlComponent>
  5. #include <QQmlContext>
  6. #include <csignal>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <iostream>
  11. #include <sys/prctl.h>
  12. #include <sys/wait.h>
  13. #include <unistd.h>
  14. #include "qmlhandler.h"
  15. using namespace std;
  16. int inpipefd[2];
  17. int outpipefd[2];
  18. char buf[1024];
  19. int main(int argc, char *argv[]) {
  20. qInfo() << "Program Start";
  21. pid_t pid = 0;
  22. char msg[256];
  23. int status;
  24. pipe(inpipefd);
  25. pipe(outpipefd);
  26. pid = fork();
  27. if (pid == 0) {
  28. // Child
  29. dup2(outpipefd[0], STDIN_FILENO);
  30. dup2(inpipefd[1], STDOUT_FILENO);
  31. dup2(inpipefd[1], STDERR_FILENO);
  32. // ask kernel to deliver SIGTERM in case the parent dies
  33. prctl(PR_SET_PDEATHSIG, SIGTERM);
  34. // Set the path to the CLI - pass argument h (help) for now
  35. // TODO: Change hardcoded path
  36. execl("../../cli/build/ccats-cli", "ccats-cli", "127.0.0.1", "--machine",
  37. (char *)NULL);
  38. exit(1);
  39. }
  40. close(outpipefd[0]);
  41. close(inpipefd[1]);
  42. // ########## Load GUI ##########
  43. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  44. // This has to be here to fix warnings
  45. QCoreApplication::setOrganizationName("CCats");
  46. QGuiApplication app(argc, argv);
  47. QQmlApplicationEngine engine;
  48. QMLHandler qmlHandler;
  49. engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
  50. QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
  51. QObject *object = component.create();
  52. return app.exec();
  53. }