Linux 将命令行参数传递给qml
我想从LinuxShell调用一个qml脚本,并将一个文本作为参数传递,如Linux 将命令行参数传递给qml,linux,qt,shell,qml,command-line-arguments,Linux,Qt,Shell,Qml,Command Line Arguments,我想从LinuxShell调用一个qml脚本,并将一个文本作为参数传递,如 ./message.qml "hello this is a message" 或 qml脚本应该显示该文本 下面的示例qml脚本可以工作,但是显示的文本(“hello”)当然是静态的。可以在qml中查询命令行参数吗 #!/usr/bin/qt5/qml import QtQuick 2.2 Rectangle { width: 1024 height: 600 Text {
./message.qml "hello this is a message"
或
qml脚本应该显示该文本
下面的示例qml脚本可以工作,但是显示的文本(“hello”)当然是静态的。可以在qml中查询命令行参数吗
#!/usr/bin/qt5/qml
import QtQuick 2.2
Rectangle {
width: 1024
height: 600
Text {
anchors.centerIn: parent
text: "Hello" // here I want to have a text which is set in the call
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit()
}
}
}
您可以使用访问命令行参数,例如在我的示例中,如果我执行:
/usr/bin/qml message.qml "hello this is a message"
Qt.application.arguments[index]
中的索引可能因调用qml执行的方式而异
/usr/bin/qml message.qml "hello this is a message"
#!/usr/bin/qt5/qml
import QtQuick 2.2
Rectangle {
width: 1024
height: 600
Text {
anchors.centerIn: parent
text: Qt.application.arguments[2] // here I want to have a text which is set in the call
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit()
}
}
}