|
You last visited: Today at 09:50
Advertisement
Problem displaying entity names
Discussion on Problem displaying entity names within the Nostale forum part of the MMORPGs category.
12/18/2020, 23:12
|
#1
|
elite*gold: 0
Join Date: May 2020
Posts: 370
Received Thanks: 450
|
Problem displaying entity names
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
|
#2
|
elite*gold: 0
Join Date: Jan 2017
Posts: 475
Received Thanks: 192
|
Use different encoding
|
|
|
12/19/2020, 00:16
|
#3
|
elite*gold: 0
Join Date: May 2020
Posts: 370
Received Thanks: 450
|
I've tryed using UTF-16 but it's displaying some random chinese characters
|
|
|
12/19/2020, 00:37
|
#4
|
elite*gold: 0
Join Date: Oct 2018
Posts: 257
Received Thanks: 207
|
What you want to use is UTF-8
|
|
|
12/19/2020, 08:41
|
#5
|
elite*gold: 0
Join Date: May 2020
Posts: 370
Received Thanks: 450
|
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
|
#6
|
elite*gold: 0
Join Date: Mar 2015
Posts: 871
Received Thanks: 1,229
|
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
|
#7
|
elite*gold: 0
Join Date: May 2020
Posts: 370
Received Thanks: 450
|
I managed to make it work aswell with QString::fromLatin1 but thanks anyways
|
|
|
01/09/2021, 22:15
|
#8
|
elite*gold: 0
Join Date: May 2020
Posts: 370
Received Thanks: 450
|
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
|
|
|
01/09/2021, 22:34
|
#9
|
elite*gold: 64
Join Date: May 2011
Posts: 1,229
Received Thanks: 854
|
Why don't simply use the File-Class of QT?
(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
|
#10
|
elite*gold: 0
Join Date: May 2020
Posts: 370
Received Thanks: 450
|
I didn't even know that Qt had that class  . It worked very well ty for your help
|
|
|
01/10/2021, 16:38
|
#11
|
elite*gold: 64
Join Date: May 2011
Posts: 1,229
Received Thanks: 854
|
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.
|
|
|
 |
Similar Threads
|
Beginner Java: Displaying a 2D background
02/19/2012 - Tutorials - 0 Replies
Displaying a 2D Background
Difficulty: 2 / 10.
Assumed Knowledge: basic knowledge of the Java language.
Information: This tutorial will teach you how to create a basic API and display an image.
What is an API..?
An application programming interface (API) is an interface implemented by a software program that enables it to interact with other software. It facilitates interaction between different software programs similar to the way the user interface facilitates interaction between...
|
C# displaying charname problem
04/08/2011 - SRO Coding Corner - 5 Replies
Hey guys,
I've got some problems at the moment, im creating a information bar , or how to call it that shows my HP and MP and name ect ect...
But at the moment it only display the first letter of my name and servername, sometimes it shows everything and sometimes it shows nothing ...
Here is the code for my char name
string charactername = mem.ReadString(0xF9E9B8);
|
[Question]Displaying Packets
01/11/2009 - CO2 Private Server - 1 Replies
just asking how to put that option back in there to display packets in the console
Help is appreciated and THanx
|
All times are GMT +1. The time now is 09:51.
|
|