Heya, now im trying to read/write stuff to a file and im facing the next issue, when i write to a file from a QString the entity name is being saved and displayed correctly on the file but when I read that same name from the file and try to convert it to a QString using QString::fromLatin1 or QString::fromLocal8Bit characters like "á, é, í, ó, ú" are not being displayed correctly.
Example of writing:
Code:
std::ofstream ofile;
// Open the file for writing
ofile.open(filename.toStdString().c_str(), std::ofstream::out | std::ofstream::trunc);
// Error check
if (!ofile.is_open())
{
MessageBoxA(NULL, "Failed saving the file.", "Error", MB_ICONERROR);
return;
}
// Write to the file
// Imagine we have something like QString entityname = "Dánder"
ofile << entityname.toStdString();
// Close the file
ofile.close();
Example of reading:
Code:
std::ifstream ifile;
// Open the file for reading
ifile.open(filename.toStdString().c_str());
// Error check
if (!ifile.is_open())
{
MessageBoxA(NULL, "Failed loading the file.", "Error", MB_ICONERROR);
return;
}
// Read the string
std::string name;
ifile >> name;
MessageBoxA(NULL, name.c_str(), "", 0);
// Close the file
ifile.close();
If someone can help me i'd be very thankfull :)