Unsolved How to separate channels when using qprocess?
-
Hey! I mean how can I assign different signals to different buttons? I'm very very new at c++ so, here is my code:
scriptlauncher.h
#ifndef SCRIPTLAUNCHER_H #define SCRIPTLAUNCHER_H #include <QObject> #include <QProcess> class ScriptLauncher : public QObject { Q_OBJECT public: explicit ScriptLauncher(QObject *parent = 0); Q_INVOKABLE void launchScript(); private: QProcess *m_process; }; #endif
main.cpp
#include "scriptlauncher.h" #include <QQmlContext> ... ScriptLauncher launcher; QQmlApplicationEngine engine; QQmlContext *kotu = engine.rootContext(); kotu->setContextProperty("sLkotu", &launcher); QQmlContext *orta = engine.rootContext(); orta->setContextProperty("sLorta", &launcher); QQmlContext *iyi = engine.rootContext(); iyi->setContextProperty("sLiyi", &launcher); ...
scriptlauncher.cpp
#include "scriptlauncher.h" ScriptLauncher::ScriptLauncher(QObject *parent) : QObject(parent), m_process(new QProcess(this)) { } void ScriptLauncher::launchScript() { m_process->start("python3 screen.py"); }
main.qml
... Connections { target: mouseArea onClicked: sLiyi.launchScript() } Connections { target: mouseArea1 onClicked: sLorta.launchScript() } Connections { target: mouseArea2 onClicked: sLkotu.launchScript() }
codes does work but I don't know how to separete them. Thanks in advance!
-
@Bege
i think you are over-complicating things here.Either you pass a parameter to your
launchScript()
method.Or you create different launcher instances:
QQmlApplicationEngine engine; ScriptLauncher sLkotu("..."); engine.rootContext()->setContextProperty("sLkotu", &sLkotu); ScriptLauncher sLorta("..."); engine.rootContext()->setContextProperty("sLorta", &sLorta); ScriptLauncher sLiyi("..."); engine.rootContext()->setContextProperty("sLiyi", &sLiyi);
-
@raven-worx hey! Thanks for the help but sadly I couldn't make different launchers work.. How can I pass parameters to launcher as different individual? or maybe you can show me the way to make that launchers work? Sorry for this kinda noobs question. And before I go here is your second; Thanks!
-
@Bege
WHAT doesn't work?!
How it is EXACTLY supposed to work? -
This post is deleted! -
@raven-worx Sorry haven't look carefuly. Figured it out thanks to you..