Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Q: Execute terminal command from an application

    Reply
    Page 1 of 2 | 1   2   | Next
    KullasH | # 1 | 2013-01-29, 14:52 | Report

    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!

    Edit | Forward | Quote | Quick Reply | Thanks

     
    coderus | # 2 | 2013-01-29, 14:56 | Report

    what is your application language?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    KullasH | # 3 | 2013-01-29, 15:00 | Report

    Oops..

    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?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    marxian | # 4 | 2013-01-29, 15:35 | Report

    See this post: http://talk.maemo.org/showpost.php?p...45&postcount=2

    Edit | Forward | Quote | Quick Reply | Thanks

     
    KullasH | # 5 | 2013-01-29, 15:47 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    marxian | # 6 | 2013-01-29, 16:10 | Report

    Originally Posted by KullasH View Post
    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".

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to marxian For This Useful Post:
    qwazix, rcolistete

     
    KullasH | # 7 | 2013-01-29, 17:10 | Report

    Sweetness! Thank you very much mate.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to KullasH For This Useful Post:
    marxian

     
    KullasH | # 8 | 2013-04-29, 19:18 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    marxian | # 9 | 2013-04-29, 20:01 | Report

    Originally Posted by KullasH View Post
    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");

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to marxian For This Useful Post:
    Dave999

     
    KullasH | # 10 | 2013-04-30, 03:02 | Report

    EDIT: Alles goed! Just noticed that of course the SSH commands can not work if not using N9 itself for testing.

    Originally Posted by marxian View Post
    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.

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by KullasH; 2013-04-30 at 04:45.

     
    Page 1 of 2 | 1   2   | Next
vBulletin® Version 3.8.8
Normal Logout