我正在尝试读取从QT application
using创建的现有文件QDataStream
,我正在使用C#
它来读取它,但我无法正常工作。
这是我用于读取文件的 C# 代码:我没有收到任何错误,只是一个空白MessageBox
.
如何QT
使用 C# 读取使用 QDataStream 创建的文件?
FileStream readStream;
string msg = null;
try {
readStream = new FileStream(@"C:/MyUsers/SomeFolder/UserNameList.txt", FileMode.Open);
BinaryReader readBinary = new BinaryReader(readStream);
msg = readBinary.ReadString();
MessageBox.Show(msg);
readStream.Close();
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
这是用于将文件写入QT
.
QFile UsersNameListFile ("C:/MyUsers/SomeFolder/UserNameList.txt");
QString userName = "SomeName";
QHash<QString, QString> listOfUsers;
if(!listOfUsers.contains(userName))
{
listOfUsers.insert(userName, "Some Text");
if (UsersNameListFile.open(QIODevice::WriteOnly))
{
QDataStream writeToFile(&UsersNameListFile);
writeToFile.setVersion(QDataStream::Qt_5_1);
writeToFile << listOfUsers;
UsersNameListFile.flush();
UsersNameListFile.close();
}
}