#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
#include "scriptlauncher.h" ScriptLauncher::ScriptLauncher(QObject *parent) : QObject(parent), m_process(new QProcess(this)) { } void ScriptLauncher::launchScript() { m_process->start("sh script.sh"); }
#include "scriptlauncher.h" ... ScriptLauncher launcher; QDeclarativeContext *context = view->rootContext(); context->setContextProperty("scriptLauncher", &launcher);
ToolButton { id: myButton x: 121 y: 410 width: 119 height: 62 onClicked: scriptLauncher.launchScript() }