void Application::initQML() { /** A QML-Cpp kommunikációhoz használt QMLData obejktumokat létre kell * hozni a QML felület számára.*/ QMap<QString,QMLData>::iterator iter; for(iter = qmlDataMap.begin(); iter != qmlDataMap.end(); ++iter) { engine.rootContext()->setContextProperty(iter.key(), &iter.value()); } engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); auto rootObjects = engine.rootObjects(); if (rootObjects.size() == 0) { qWarning() << "HIBA: Nem sikerült létrehozni a QML környezetet."; } rootObject = rootObjects.first(); customPlotPtr = (QCustomPlot*)rootObject->findChild<QObject*>("customPlot"); auto mainWindowPtr = rootObject->findChild<QObject*>("MainWindow"); eventhandler.setMainWindowPtr(mainWindowPtr); QObject::connect(rootObject, SIGNAL(connectCommandCpp()), &eventhandler, SLOT(connectCommand())); QObject::connect(rootObject, SIGNAL(connectCommandCpp()), this, SLOT(connectToServer())); QObject::connect(rootObject, SIGNAL(hvEnableCommandCpp()), &eventhandler, SLOT(hvEnableCommand())); QObject::connect(rootObject, SIGNAL(hvEnableCommandCpp()), this, SLOT(hvenCommand())); QObject::connect(rootObject, SIGNAL(driveEnableCommandCpp()), &eventhandler, SLOT(driveEnableCommand())); QObject::connect(rootObject, SIGNAL(driveEnableCommandCpp()), this, SLOT(drenCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), &eventhandler, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), this, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(testCommandCpp()), this, SLOT(testCommand())); QObject::connect(rootObject, SIGNAL(vdemandSliderChanged(QVariant )), this, SLOT(vdemandChanged(QVariant ))); }
MainApplication::MainApplication(int argc, char *argv[]) : QApplication(argc, argv), simulator(12345), engine(), history(), communication(), robot(history, communication), handler(robot, *engine.rootContext(), history) { // Szimulátor indítása simulator.start(0.3F); // Csatlakozás a szimulátorhoz. communication.connect(QStringLiteral("localhost"),12345); // Szimulálunk egy history változást, mert attól kezdve léteznek a QML oldalon // a C++ oldalról származó változók. (Különben referencia hibákat kapnánk a QML oldalon // egészen addig, amíg az első üzenet meg nem jönne a szimulátortól. //handler.historyChanged(); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // A QML gyökérelemre szükségünk van ahhoz, hogy tudjunk hivatkozni a QML-es elemekre. auto rootObjects = engine.rootObjects(); if (rootObjects.size() == 0) { qDebug() << "HIBA: Nem sikerült létrehozni a QML környezetet."; return; } // A QML környezet is felállt, bekötjük a signalokat a QML és C++ oldal között. QObject *rootObject = rootObjects[0]; // A handler beköti a saját signaljait. handler.ConnectQmlSignals(rootObject); // Bekötjük a nyomógombok signaljait. QObject::connect(rootObject, SIGNAL(resetCommandCpp()), &handler, SLOT(resetCommand())); QObject::connect(rootObject, SIGNAL(accelerateXCommandCpp()), &handler, SLOT(accelerateXCommand())); QObject::connect(rootObject, SIGNAL(accelerateYCommandCpp()), &handler, SLOT(accelerateYCommand())); QObject::connect(rootObject, SIGNAL(slowDownXCommandCpp()), &handler, SLOT(slowDownXCommand())); QObject::connect(rootObject, SIGNAL(slowDownYCommandCpp()), &handler, SLOT(slowDownYCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), &handler, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(testCommandCpp()), &handler, SLOT(testCommand())); QObject::connect(rootObject, SIGNAL(defaultCommandCpp()), &handler, SLOT(defaultCommand())); }