| 1   2   | Next
maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   MeeGo / Harmattan (https://talk.maemo.org/forumdisplay.php?f=45)
-   -   Q: Execute terminal command from an application (https://talk.maemo.org/showthread.php?t=88858)

KullasH 2013-01-29 14:52

Q: Execute terminal command from an application
 
Hello!

I have done few basic applications for my own usage and fun. I haven't found any kind of information of how to execute a command through terminal? For instance, let's say that I would like to simply display a basic functions such as showing the IP.

How am I able to do that? Do I need to call the command through SSH or directly into terminal?

Appreciated! :)

coderus 2013-01-29 14:56

Re: Q: Execute terminal command from an application
 
what is your application language? :)

KullasH 2013-01-29 15:00

Re: Q: Execute terminal command from an application
 
Oops.. :o

Well, mainly I've used QML and I would like to stick with that because it was the easiest for me to understand for some reason.

But if it can not be done with QML then any other options? :)

marxian 2013-01-29 15:35

Re: Q: Execute terminal command from an application
 
See this post: http://talk.maemo.org/showpost.php?p...45&postcount=2

KullasH 2013-01-29 15:47

Re: Q: Execute terminal command from an application
 
Nice one, exactly what I was looking for. Thank you very much! :)

But I have a question which I couldn't figure out - at least not yet. Let's say I'd like to list the current files and folders in directory "/home/user/" for example, how I do that?

EDIT * I do know that using 'ls' or 'ls -a' lists the files and folders, but how I make the list using using TextArea for example.

I don't actually need that one yet, but for future projects if I need it some day.

marxian 2013-01-29 16:10

Re: Q: Execute terminal command from an application
 
Quote:

Originally Posted by KullasH (Post 1318785)
Nice one, exactly what I was looking for. Thank you very much! :)

But I have a question which I couldn't figure out - at least not yet. Let's say I'd like to list the current files and folders in directory "/home/user/" for example, how I do that?

EDIT * I do know that using 'ls' or 'ls -a' lists the files and folders, but how I make the list using using TextArea for example.

I don't actually need that one yet, but for future projects if I need it some day.

The example at the bottom of that post (see https://github.com/marx1an/qt-compon...rocessPage.qml) shows exactly that use case, except a Label (inside a Flickable) is used to display results instead of a TextArea. Here's a simple example using a TextArea:

Code:

Page {
    id: root

    Process {
        id: process

        workingDirectory: "/home/user"
        command: "ls"
        onFinished: textArea.text = process.readAllStandardOutput()
    }

    TextArea {
        id: textArea

        anchors.centerIn: parent
    }

    Component.onCompleted: process.start()
}

To list files in /home/user, you can either set the workingDirectory property of the Process element to "/home/user" and set the command property to "ls", or you can simply set the command property to "ls /home/user".

KullasH 2013-01-29 17:10

Re: Q: Execute terminal command from an application
 
Sweetness! Thank you very much mate. :)

KullasH 2013-04-29 19:18

Re: Q: Execute terminal command from an application
 
Hmm.. I have a problem that I just can not figure out by myself.

When I use your qdeclarativesettings.h and *.cpp files it complains about the <QDeclarativeProcess> in main.cpp file. Well, I found your qdeclarativeprocess.h and *.cpp files and that made it.

However it now complains about "...\main.cpp:13: error: no matching function for call to 'qmlRegisterUncreatableType(const char [24], int, int, const char [10])'". Here's the main.cpp file:

Code:

#include <QtGui/QApplication>
#include <QtDeclarative>
#include "qmlapplicationviewer.h"
#include "qdeclarativeprocess.h"
#include "qdeclarativesettings.h"

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QmlApplicationViewer viewer;

    qmlRegisterType<QDeclarativeProcess>("org.component.Processes", 1, 0, "Process");
    qmlRegisterUncreatableType<QDeclarativeProcessEnums>("org.component.Processes", 1, 0, "Processes");

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qml/filecontrol/main.qml"));
    viewer.showExpanded();

    return app->exec();
}

If I try without the line it complains about (line 13: qmlRegisterUncreatableType<QDeclarativeProcessEnum s>) it works without any problems. Well, then it only displays onError statement in my *.qml file and not the onFinished state.

Any advice what I'm doing wrong here? I have added *.cpp and *.h files in *.pro file so that should not be a problem.

marxian 2013-04-29 20:01

Re: Q: Execute terminal command from an application
 
Quote:

Originally Posted by KullasH (Post 1339980)
Hmm.. I have a problem that I just can not figure out by myself.

When I use your qdeclarativesettings.h and *.cpp files it complains about the <QDeclarativeProcess> in main.cpp file. Well, I found your qdeclarativeprocess.h and *.cpp files and that made it.

However it now complains about "...\main.cpp:13: error: no matching function for call to 'qmlRegisterUncreatableType(const char [24], int, int, const char [10])'". Here's the main.cpp file:

Code:

#include <QtGui/QApplication>
#include <QtDeclarative>
#include "qmlapplicationviewer.h"
#include "qdeclarativeprocess.h"
#include "qdeclarativesettings.h"

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QmlApplicationViewer viewer;

    qmlRegisterType<QDeclarativeProcess>("org.component.Processes", 1, 0, "Process");
    qmlRegisterUncreatableType<QDeclarativeProcessEnums>("org.component.Processes", 1, 0, "Processes");

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qml/filecontrol/main.qml"));
    viewer.showExpanded();

    return app->exec();
}

If I try without the line it complains about (line 13: qmlRegisterUncreatableType<QDeclarativeProcessEnum s>) it works without any problems. Well, then it only displays onError statement in my *.qml file and not the onFinished state.

Any advice what I'm doing wrong here? I have added *.cpp and *.h files in *.pro file so that should not be a problem.

There is a missing argument (the error string) in your call to qmlRegisterUncreatableType. The error string can be anything you like, for example:

Code:

qmlRegisterUncreatableType<QDeclarativeProcessEnums>("org.component.Processes", 1, 0, "Processes", "Cannot be created in QML");

KullasH 2013-04-30 03:02

Re: Q: Execute terminal command from an application
 
EDIT: Alles goed! Just noticed that of course the SSH commands can not work if not using N9 itself for testing. :)

Quote:

Originally Posted by marxian (Post 1339988)
There is a missing argument (the error string) in your call to qmlRegisterUncreatableType. The error string can be anything you like, for example:

Code:

qmlRegisterUncreatableType<QDeclarativeProcessEnums>("org.component.Processes", 1, 0, "Processes", "Cannot be created in QML");

Ah, missed that one. Never ever used qmlRegisterUncreatableType and your example did not include the error string so... But thanks anyways! :)

It still gives me only error no matter what command I'm trying to execute. I've tried 'ls' 'ls -a' 'ls /' etc. I've also tried with and without the workingDirectory property. I've tried to call the Process QML from Page QML's Component.onCompleted and on button click. Neither of 'em have worked.


| 1   2   | Next
All times are GMT. The time now is 10:43.

vBulletin® Version 3.8.8