Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 将命令行参数传递给qml_Linux_Qt_Shell_Qml_Command Line Arguments - Fatal编程技术网

Linux 将命令行参数传递给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 {

我想从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 {
        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()
        }
    }
}