You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
996 B
Markdown
55 lines
996 B
Markdown
Inspired by http://www.xargs.com/qml/process.html
|
|
|
|
Add to project.pro:
|
|
|
|
```
|
|
HEADERS += \
|
|
../../qml-process/process.h
|
|
```
|
|
|
|
Add to main.cpp
|
|
|
|
```c++
|
|
#include <QtQml>
|
|
#include "../../qml-process/process.h"
|
|
|
|
// in main:
|
|
qmlRegisterType<Process>("Process", 1, 0, "Process");
|
|
```
|
|
|
|
Use in QML:
|
|
|
|
```
|
|
import Process 1.0
|
|
|
|
# ...
|
|
|
|
Component.onCompleted: {
|
|
process.start("some-bin", ["some args"])
|
|
}
|
|
|
|
|
|
Text {
|
|
id: output
|
|
x: 0
|
|
y: 0
|
|
text: ""
|
|
}
|
|
|
|
|
|
Process {
|
|
id: process
|
|
//onReadyRead: {output.text += readAll();output.text += readAllStandardOutput();}
|
|
onReadyReadStandardError: {output.text += readAllStandardError();}
|
|
onFinished: {
|
|
console.log("finished", exitCode)
|
|
output.text += exitCode.toString()
|
|
console.log(readAllStandardError());
|
|
}
|
|
onErrorOccurred: {
|
|
console.log("error!");
|
|
output.text += readAllStandardError()
|
|
}
|
|
}
|
|
```
|