Problem displaying entity names

12/18/2020 23:12 Hatz~#1
Hello, i'm trying to display monster names on a qt gui but there are some special characters like "á, é, í, ó, ú and ñ" that are not being displayed correctly, does anyone know how to fix it? I've tried to google for a solution but most of the things i've found are related to console changes.

Image:
12/19/2020 00:00 Limoo#2
Use different encoding
12/19/2020 00:16 Hatz~#3
I've tryed using UTF-16 but it's displaying some random chinese characters
12/19/2020 00:37 Apourtartt#4
What you want to use is UTF-8
12/19/2020 08:41 Hatz~#5
Uhm but isn't char strings already UTF-8? Sorry if this might looks like a very beginner question xD

Edit: so i've tried printing the names on a MessageBox and it was showing correctly there so the problem might be on the QString that is not on UTF-8 right? I've tried to use the method QString::fromUtf8() but didn't work

This is how im reading the char string:
Code:
MessageBoxA(NULL, mob->MonsterNamePtr->name, "", 0); // This shows correct name
ui->listWidget_2->addItem(mob->MonsterNamePtr->name); // This shows incorrect name
12/20/2020 23:12 WalrossGreat#6
The strings in game are encoded with your default windows encoding (which is used by MessageBoxA), the QString operates on utf-8, you can use the QString::fromLocal8Bit to convert the native encoded char* to utf-8 QString
12/20/2020 23:51 Hatz~#7
I managed to make it work aswell with QString::fromLatin1 but thanks anyways :)
01/09/2021 22:15 Hatz~#8
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:

Example of reading:

If someone can help me i'd be very thankfull :)
01/09/2021 22:34 BladeTiger12#9
Why don't simply use the File-Class of QT?
[Only registered and activated users can see links. Click Here To Register...]

(All untested)

Code:
    QFile file("out.txt");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return;

    QTextStream out(&file);
    out << "The magic number is: " << 49 << "\n";
Else try it with std::wstring instead of std::string.

Code:
QString sMyQtString = "test";

std::wofstream f(L"C:\\some file.txt");
f << sMyQtString.toStdWString();
f.close();
01/10/2021 15:31 Hatz~#10
I didn't even know that Qt had that class :lul:. It worked very well ty for your help :)
01/10/2021 16:38 BladeTiger12#11
Qt has everything you'll need. Really everything. Even 3D stuff / game rendering / Microcontroller etc... When I used it I never had one row with STD-library stuff.