4
I’m having a problem encoding strings on Qt
. By showing something in a QMessageBox
or give a drawText
in a paintEvent
, my strings come out badly formatted, as if they were not in the correct encoding.
This is how it appears to me:
Code of the Linechart:
if(bTitle){
p.setPen(titleColor);
p.drawText((width()/2 - (getTitle().size() * 5)),40, getTitle());
}
and getTitle is:
QString LineChart::getTitle(){
return this->Title;
}
Use Debian
7.1 64 bits.
Does anyone know how to solve?
Hello Avelino, could you post relevant parts of your code? Also show the output of
file -i [nome do arquivo de código fonte]
for relevant files. The shortest way to success is to write and read everything with UTF-8 (see that article in English).– Anthony Accioly
Still on that front, for fixed strings it is always good to fix the encoding:
QString str = QString::fromUtf8("Instruções");
– Anthony Accioly
Hello, This is the output for my files: avelino@amn:~/Projects/Qt/Flappybird$ file -i Animation.cpp Animation.cpp: text/x-c; charset=utf-8
– Avelino
I tried using: Qstring str = Qstring::fromUtf8("text"); Qmessagebox::information(this, tr(str)); but it doesn’t let because tr has to receive a char array or pointer.
– Avelino
I used a trUtf8() in Qmessagebox and solved the problem. But paintEvent still persists. I wonder what can be?
– Avelino
Again,
this->Title
is being set up withfromUtf8
ortrUtf8
?– Anthony Accioly
I was doing: void Linechart::setTitle(Qstring Title){ this->Title = Title; } Now I did so, and it worked: void Linechart::setTitle(const char * Title){ this->Title = Qstring:::fromUtf8(Title); }
– Avelino
Man, very grateful for your help. Documentation has served. =)
– Avelino