I'm trying to read an existing file that was created from a QT application
using QDataStream
, I'm using C#
to read it but I can not make work.
Here is my C# code for reading the file: I get no errors just a blank MessageBox
.
How can I read file created in QT
with QDataStream using C#?
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());
}
Here is the code used for writing the file in 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();
}
}