View Single Post
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#28
I've now added a QDeclarativeProcess plugin. This makes the the QProcess API accessible via QML. It doesn't depend on qt-components-hildon, so if you have a QML project and want to use QProcess, feel free to use my code.

Example:

Code:
import QtQuick 1.0
import org.hildon.components 1.0

Page {
    id: root

    title: qsTr("Process page")

    Process {
        id: process

        processEnvironment: { "PATH": "/usr/bin:/usr/local/bin", "USER": "stuart" }
        workingDirectory: "/home/stuart/Development/QtProjects"
        onError: resultLabel.text = "<font color='red'>" + qsTr("Error") + "</font>"
        onFinished: resultLabel.text = process.readAllStandardOutput()
    }

    Column {
        id: column

        spacing: 10

        anchors {
            left: parent.left
            right: parent.right
            top: parent.top
            margins: platformStyle.paddingNormal
        }

        Label {
            text: qsTr("Working directory") + ": " + process.workingDirectory
        }

        Label {
            text: "PATH: " + process.processEnvironment.PATH + ", USER: " + process.processEnvironment.USER
        }

        Label {
            text: qsTr("Command") + ":"
        }

        Row {
            spacing: platformStyle.paddingNormal

            TextField {
                id: commandEdit

                width: 300
                text: "echo hello world"
                onTextChanged: process.command = text
            }

            Button {
                id: startButton

                text: qsTr("Start")
                enabled: process.state === Processes.NotRunning
                onClicked: process.start()
            }

            Button {
                id: stopButton

                text: qsTr("Cancel")
                enabled: process.state === Processes.Running
                onClicked: process.terminate()
            }

        }

        Label {
            text: qsTr("Result") + ":"
        }
    }

    Flickable {
        id: flicker

        anchors {
            top: column.bottom
            left: parent.left
            right: parent.right
            bottom: parent.bottom
            margins: platformStyle.paddingNormal
        }
        clip: true
        contentHeight: resultLabel.height + platformStyle.paddingNormal

        Label {
            id: resultLabel

            width: parent.width
            wrapMode: Text.WordWrap
            color: "green"
        }
    }

    ScrollDecorator {
        flickableItem: flicker
    }
}
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 

The Following 3 Users Say Thank You to marxian For This Useful Post: