给定 bash 脚本中的一个字符串变量,其中包含一堆换行符 '\n',如何用字符串“abc\n”替换这些换行符?或者换句话说,如何在每个换行符前面插入“abc”?
主页
/
user-21198577
Michael21's questions
Michael21
Asked:
2023-11-05 20:23:52 +0800 CST
import QtQuick
import QtQuick.Controls 2.15
import QtQuick.Layouts 6.3
Page {
width: root.width
height: root.height
visible: true
background: Rectangle {
color: "white"
}
Text{
id: stageText
anchors.horizontalCenter: parent.horizontalCenter
topPadding: root.height / 4
font.pixelSize: 26
text: ""
color: "black"
}
ColumnLayout {
width: parent.width
height: parent.height
scale: root.width / 1000.0
RowLayout{
Layout.alignment: Qt.AlignCenter
spacing: 0
id: visualizeRow
property string myArr : hammingCode.getDataStr();
Repeater {
model: visualizeRow.myArr.length
Rectangle {
id: bit
width: 50
height: 50
Text {
anchors.centerIn: parent
text: visualizeRow.myArr.charAt(index)
color: "black"
}
border.width: 1
color: "white"
}
}
Component.onCompleted: {
stageText.text = "Encoding";
hammingCode.encodeData(true);
}
}
}
Connections{
target: hammingCode
function onTurnBitOff(index){
bit[index].color = "black";
}
function onTurnBitOn(index){
bit[index].color = "red";
}
//put signals from c++ here that change visual stuff and shit
}
}
我有一个页面,它使用 Repeater 从“0”和“1”的字符串创建一个数组,它看起来像这样: 应用程序屏幕截图
我想做的是更改某个矩形的颜色,访问连接到 C++ 信号的 Connections 函数中给定索引处的某个矩形。
函数中的代码不起作用(它说“位”未定义),但说明了我想要实现的目标。如何才能实现这一目标?