PDA

View Full Version : How can I get a filename from a different encoding?



Pepe
27th March 2007, 02:23
This is in Windows.

If I open a filename with Chinese or Russian (or whatever) characters using the QFileDialog, my program gets the proper filename.

But if this file is passed from the command line (argv) I get "?" instead of those characters.

What do I have to do to get the proper name? What's the encoding that Windows uses to pass filenames?

wysota
27th March 2007, 07:55
Most likely it's unicode or some utf variant. You have to tell QString what is the source encoding so that it can transform the data to Unicode. First thing I'd try is to use QString::fromLocal8Bit().

Pepe
27th March 2007, 15:41
There's no way.

I tried with QString::fromLocal8Bit(), QTextCodec::codecForLocale(), QTextCodec::codecForName("utf8") and QTextCodec::codecForName("utf16"). Nothing, the filename is not properly passed.

I'm stuck.

Other programs can open this file from command line (argv) without problems.

wysota
27th March 2007, 19:26
But what encoding did you try to set?

Pepe
28th March 2007, 00:18
My Windows XP is configured to Spanish language (I don't know what encoding Windows uses). I have some files with Russian,Chinese or Japanese characters.

I can't find a way that a Qt program opens those files. I tried all conversions I previously said. There's no way, the non latin characters are converted to "?" (better say, the non latin characters are always "?", I print the filename to the console before trying any conversion and it shows "?").

I looked at the sources of qt-assistant. It uses QString::fromLocal8Bit() to convert the arguments in argv to unicode.

I made the following test: I created an html file with only latin characters, and tell the windows explorer to open it with assistant. It opens without problems. Now I change the name of the file, using cyrilic characters. I try to open again, but assistant shows an empty page.

So I start thinking that Qt can't open this kind of filenames.

But other windows applications anyhow open them without problems.