Question

I'm writing a program in spanish. I want to tell the user that a file has been loaded. In spanish that is:

ui->teLog->append("Se cargó el archivo: " + filename);

However the spanish parts gets outputted as:

Se cargó el archivo:

I know the problem is the encoding (like I need to tell the program this is UTF8, I think). Is there anyway to do this?

Was it helpful?

Solution

The normal QString constructor assumes you're writing ASCII characters. If you use QString::fromUtf8() in this case it should work:

ui->teLog->append(QString::fromUtf8("Se cargó el archivo: ") + filename);

Also:

QTextCodec::setCodecForCStrings( QTextCodec::codecForName("utf8") );

(See this answer for more info)

OTHER TIPS

Consider writing all messages in plain english using latin1 language and using Qt translations features for converting messages into spanish. See http://qt-project.org/doc/qt-4.8/qobject.html#tr and http://qt-project.org/doc/qt-4.8/linguist-translators.html

This has several advantages:

  • your program will be translatable to other languages
  • non-spanish developers will be able to modify your code more easily (assuming that every developer knows english and only some know spanish).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top