import QtQuick import QtQuick.Window import QtQuick.Controls Window { width: 640 height: 480 visible: true title: qsTr("Hello World") // 试图将ListModel中的正则表达式传入到Component的RegExpression ListModel { id:contactModel property var regExpression1:/^[0-9]+$/ property var regExpression2:/^[a-z]+$/ property bool completed: false Component.onCompleted: { contactModel.append({"input": "0-9","value":"^[0-9]+$"}) contactModel.append({"input": "a-z","value":"^[a-z]+$"}) completed = true console.log(contactModel.get(0).input) console.log(contactModel.get(1).input) console.log(contactModel.get(0).value) console.log(contactModel.get(1).value) } onRegExpression1Changed: { if(completed) setProperty(0, "value", contactModel.regExpression1); } onRegExpression2Changed: { if(completed) setProperty(1, "value", contactModel.regExpression2); } } Component{ id:contactsDelegate TextField { placeholderText: input validator:RegularExpressionValidator {regularExpression:RegExp(value)} } } ListView { id:listView anchors.fill: parent model: contactModel delegate: contactsDelegate } }