FreeKill/src/main.cpp

62 lines
1.7 KiB
C++
Raw Normal View History

#include "qmlbackend.h"
#include "server.h"
int main(int argc, char *argv[])
{
QCoreApplication *app;
QCoreApplication::setApplicationName("FreeKill");
QCoreApplication::setApplicationVersion("Alpha 0.0.1");
QCommandLineParser parser;
parser.setApplicationDescription("FreeKill server");
parser.addHelpOption();
parser.addVersionOption();
parser.addOption({{"s", "server"}, "start server at <port>", "port"});
QStringList cliOptions;
for (int i = 0; i < argc; i++)
cliOptions << argv[i];
parser.parse(cliOptions);
bool startServer = parser.isSet("server");
ushort serverPort = 9527;
if (startServer) {
app = new QCoreApplication(argc, argv);
bool ok = false;
if (parser.value("server").toInt(&ok) && ok)
serverPort = parser.value("server").toInt();
Server *server = new Server;
if (!server->listen(QHostAddress::Any, serverPort)) {
fprintf(stderr, "cannot listen on port %d!\n", serverPort);
app->exit(1);
}
return app->exec();
}
app = new QGuiApplication(argc, argv);
2022-03-27 12:00:29 +00:00
QQmlApplicationEngine *engine = new QQmlApplicationEngine;
QmlBackend backend;
2022-03-27 12:00:29 +00:00
backend.setEngine(engine);
2022-03-27 12:00:29 +00:00
engine->rootContext()->setContextProperty("Backend", &backend);
engine->rootContext()->setContextProperty("AppPath", QUrl::fromLocalFile(QDir::currentPath()));
#ifdef QT_DEBUG
bool debugging = true;
#else
bool debugging = false;
#endif
2022-03-27 12:00:29 +00:00
engine->rootContext()->setContextProperty("Debugging", debugging);
engine->load("qml/main.qml");
int ret = app->exec();
2022-03-27 12:00:29 +00:00
// delete the engine first
// to avoid "TypeError: Cannot read property 'xxx' of null"
delete engine;
return ret;
}