| The Following User Says Thank You to flotron For This Useful Post: | ||
|
|
10-25-2012
, 07:19 PM
|
|
|
Posts: 2,141 |
Thanked: 7,705 times |
Joined on Aug 2010
@ Wigan, UK
|
#2
|
#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()
}
|
|
10-25-2012
, 07:47 PM
|
|
|
Posts: 313 |
Thanked: 262 times |
Joined on Jan 2012
@ Argentina
|
#3
|

|
|
10-25-2012
, 08:18 PM
|
|
|
Posts: 791 |
Thanked: 767 times |
Joined on Sep 2007
@ /Canada/Ontario/GTA
|
#4
|
|
|
10-25-2012
, 08:22 PM
|
|
|
Posts: 313 |
Thanked: 262 times |
Joined on Jan 2012
@ Argentina
|
#5
|
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include "scriptlauncher.h"
#include "qdeclarativecontext.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setMainQmlFile(QLatin1String("qml/untitled/main.qml"));
viewer.showExpanded();
ScriptLauncher launcher;
QDeclarativeContext *context = view->rootContext();
context->setContextProperty("scriptLauncher", &launcher);
return app->exec();
}
|
|
10-25-2012
, 08:36 PM
|
|
|
Posts: 2,141 |
Thanked: 7,705 times |
Joined on Aug 2010
@ Wigan, UK
|
#6
|
i'm stuck with this errors:
main.cpp: In function 'int main(int, char**)':
main.cpp:16: error: 'view' was not declared in this scope
This is my main.cpp
Code:#include <QtGui/QApplication> #include "qmlapplicationviewer.h" #include "scriptlauncher.h" #include "qdeclarativecontext.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer<QApplication> app(createApplication(argc, argv)); QmlApplicationViewer viewer; viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer.setMainQmlFile(QLatin1String("qml/untitled/main.qml")); viewer.showExpanded(); ScriptLauncher launcher; QDeclarativeContext *context = view->rootContext(); context->setContextProperty("scriptLauncher", &launcher); return app->exec(); }
|
|
10-25-2012
, 10:18 PM
|
|
|
Posts: 313 |
Thanked: 262 times |
Joined on Jan 2012
@ Argentina
|
#7
|
|
|
10-26-2012
, 02:40 AM
|
|
Posts: 1,429 |
Thanked: 2,075 times |
Joined on Apr 2010
@ St. Helens, England
|
#8
|
Ok! no errors.
Now, where i place the "script.sh" file? under QML "Other files"?
And then it executes with "onClicked: scriptLauncher.launchScript()"?
or i must add for ex: "onClicked: scriptLauncher.launchScript(/opt/something/string.sh)"?
| The Following User Says Thank You to sixwheeledbeast For This Useful Post: | ||
|
|
10-26-2012
, 12:08 PM
|
|
|
Posts: 313 |
Thanked: 262 times |
Joined on Jan 2012
@ Argentina
|
#9
|
|
|
10-26-2012
, 12:36 PM
|
|
|
Posts: 2,141 |
Thanked: 7,705 times |
Joined on Aug 2010
@ Wigan, UK
|
#10
|
i added the script folder with script.sh inside but (with right click to project, add existing file) when i install i explore the opt folder on phone and i only see "bin" and "qml" folders.
This is the pro file:
OTHER_FILES += \
qtc_packaging/debian_harmattan/rules \
qtc_packaging/debian_harmattan/README \
qtc_packaging/debian_harmattan/manifest.aegis \
qtc_packaging/debian_harmattan/copyright \
qtc_packaging/debian_harmattan/control \
qtc_packaging/debian_harmattan/compat \
qtc_packaging/debian_harmattan/changelog \
script/script.sh
script.path = /opt/<application_name>/script script.files += script/script.sh INSTALLS += script
![]() |
| Thread Tools | Search this Thread |
|
I have the script.sh:
ToolButton { id: myButton x: 121 y: 410 width: 119 height: 62 onClicked: { HERE I WANT TO EXECUTE THE SCRIPT } } }I must package the sh file with QT or i must write the sh script inside QML?
Bigger Icons (MetroUI)
Charging Indicator
s60.com.ar