Results 1 to 5 of 5

Thread: How can I get a filename from a different encoding?

  1. #1
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How can I get a filename from a different encoding?

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How can I get a filename from a different encoding?

    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().

  3. #3
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I get a filename from a different encoding?

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How can I get a filename from a different encoding?

    But what encoding did you try to set?

  5. #5
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I get a filename from a different encoding?

    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.

Similar Threads

  1. QFileDialog::getSaveFileName issues with filename
    By dugs in forum Qt Programming
    Replies: 2
    Last Post: 11th December 2006, 17:17
  2. How to read encoding type in XML file
    By danbr in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2006, 08:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.