在ui中创建一个lineEdit
然后
QString sss=ui->lineEdit->text();
这样就获得了lineEdit的内容,并转为了QString格式,接下来参考
https://editor.csdn.net/md/?articleId=119974326
这篇文章,
加一句
*outFile<<sss;
即可!
代码如下
void test::stringTest()
{
QString sss= ui->lineEdit->text();
system("gnome-terminal -- bash -c 'touch 1.sh'&");
QFile *myFile;
QTextStream *outFile;
QString filename="./1.sh";
myFile=new QFile(filename);
myFile->open(QIODevice::WriteOnly | QIODevice::Text);
outFile=new QTextStream(myFile);
*outFile<<"#!/bin/bash\n";
*outFile<<"ls\n";//发现当前目录是1.sh所在目录,即build目录
*outFile<<"sleep 4\n";//等4s
*outFile<<"exit 0\n";//关闭终端
myFile->close();
system("gnome-terminal -- bash -c 'chmod +x ./1.sh'&");
system("gnome-terminal -- bash -c 'vim ./1.sh'&");
}