添加保存lua脚本

master
zcy 2021-04-20 00:52:06 +08:00
parent ffe1fd9bb8
commit dd6df86cea
3 changed files with 49 additions and 18 deletions

View File

@ -84,22 +84,37 @@ Item {
Layout.leftMargin: 10 Layout.leftMargin: 10
} }
RowLayout{
Layout.columnSpan: 2
Button { Button {
id: button id: button2
text: qsTr("更新lua脚本") text: qsTr("保存lua脚本")
Layout.preferredHeight: 41 Layout.preferredHeight: 41
Layout.preferredWidth: 116 Layout.preferredWidth: 116
Layout.columnSpan: 2 Layout.leftMargin: 15
Layout.leftMargin: parent.width/2 - 41
Layout.bottomMargin: 10 Layout.bottomMargin: 10
onClicked: { onClicked: {
lua_script_text = lua_script.text lua_script_text = lua_script.text
DataWrap.SaveLuaScript(lua_script_text) DataWrap.SaveLuaScript(lua_script_text)
} }
} }
Button {
id: button
text: qsTr("更新lua脚本")
Layout.preferredHeight: 41
Layout.preferredWidth: 116
Layout.bottomMargin: 10
onClicked: {
lua_script_text = lua_script.text
DataWrap.UpdateLuaScript(lua_script_text)
}
}
}
} }
} }
@ -109,8 +124,4 @@ Item {
} }
} }
/*##^##
Designer {
D{i:2;anchors_height:600;anchors_width:800}
}
##^##*/

View File

@ -99,7 +99,7 @@ int ShareData::TestShowData()
return 0; return 0;
} }
int ShareData::SaveLuaScript(QString str) int ShareData::UpdateLuaScript(QString str)
{ {
qDebug()<<QThread::currentThreadId(); qDebug()<<QThread::currentThreadId();
mLuaScript = str; mLuaScript = str;
@ -111,4 +111,23 @@ int ShareData::SaveLuaScript(QString str)
} }
} }
int ShareData::SaveLuaScript(QString s)
{
QFile file("Test.lua"); //---打开文件
if (file.open(QIODevice::WriteOnly) )
{
//---待存入文本文件的字符串。
//-----将数据写入文件
qint64 LineLen = file.write(s.toStdString().c_str(), s.size());
//----同上,写入文件失败,将返回 -1
if (-1 != LineLen)
{
//---输出写入文件的内容
return -1;
}
}
//----关闭文件
file.close();
}

View File

@ -42,6 +42,7 @@ public:
Q_INVOKABLE int CloseSerial(); Q_INVOKABLE int CloseSerial();
Q_INVOKABLE int TestLua(); Q_INVOKABLE int TestLua();
Q_INVOKABLE int TestShowData(); Q_INVOKABLE int TestShowData();
Q_INVOKABLE int UpdateLuaScript(QString);
Q_INVOKABLE int SaveLuaScript(QString); Q_INVOKABLE int SaveLuaScript(QString);
QString _txt = "hello world\r\n"; QString _txt = "hello world\r\n";