Results 1 to 6 of 6

Thread: Problems with korean symbols in file path

  1. #1
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Problems with korean symbols in file path

    I have a Windows application written in LabVIEW, where path arguments are passed to a DLL which uses Qt. Inside the DLL, I create a QString (passing the char* from LabVIEW to the constructor) to open a QFile.

    When the path contains Korean symbols, conversion to QString seems to fail in some way. I added

    Qt Code:
    1. QTextCodec* codec = QTextCodec::codecForName("EUC-KR");
    2. QTextCodec::setCodecForCStrings(codec);
    To copy to clipboard, switch view to plain text mode 
    and also tried

    Qt Code:
    1. QTextCodec* codec = QTextCodec::codecForName("UTF-8");
    2. QTextCodec::setCodecForCStrings(codec);
    To copy to clipboard, switch view to plain text mode 

    before using QString::QString(const char*), but the problems remain. The first try returns a 0-codec (not found), the second try still fails to convert.

    I also tried using QString::fromLocal8Bit(), but even on my english machine this returns a string of size zero. Maybe something to do with the '\' character in the path?

    On the National Instruments forum (LabVIEW) I got the following reply concerning the way LabVIEW passes the string to my DLL:

    I don't think that we reinterpret your string in anyway, just reformat the data so that it can be passed to your dll.

    So assuming you are getting text from, say, keyboard editing, the text should be in the ANSI codepage that the system is running under. That is, if you are running Windows using an English locale, it will be codepage 1252 (Windows Western, Latin 1), if you are running Windows with a Korean codepage iirc it will be codepage 949, Unified Hangul code.

    If you are filling the string with data that you get from an instrument or some other fashion, it could really be anything.

    Here is a list of the codepages that Windows knows about

    http://msdn2.microsoft.com/en-us/lib...46(VS.85).aspx


    I do have some experience with Qt as well, and I think that the function you are looking for to create, say, a QString from this is:

    QString::fromLocal8Bit

    but I am not 100% certain about this as I am not a Qt expert.

    Jeff Peters
    LabVIEW R & D
    The important thing to note here is everything worked fine when I used fopen (C) or std streams instead of Qt to read the files. I changed them to QDataStreams because of some advantages and would not like to go back in time. But it also means something must be happening in the part where the QString is created from my char*, and not earlier.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    462
    Thanked 65 Times in 61 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with korean symbols in file path

    The LabView people are correct - oyu have to find out the system locale and then convert it to unicode with the help of QTextCodec::convertToUnicode()

    QString::QString(const char*) converts from ascii (take a look in the docs !)

  3. #3
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems with korean symbols in file path

    That's a good remark, I kept on using ASCII combined with different codecs, not really knowing what was going wrong.

    So is this what I need to do? I would like to check with you guys first, otherwise I need to keep on sending test files to Korea . It works on my system, but no idea what it will be there.

    Qt Code:
    1. const char* c_str = ...; //Coming from LabVIEW
    2. QTextCodec* codec = QTextCodec::codecForLocale();
    3. QString converted = codec->toUnicode(c_str, strlen(c_str), 0);
    To copy to clipboard, switch view to plain text mode 

    Also, I was wondering if you need to include any additional files on deployment to have access to all codecs. For example, when I use QTextCodec::codecForName("EUC-KR") in a Qt program, a successful codec is returned. If I do the same in my LabVIEW controlled DLL, 0 is returned.

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    462
    Thanked 65 Times in 61 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with korean symbols in file path

    Some codec are only available as plugins - see documentation how to deploy them and also take a look into qt-4/plugins/codecs

  5. The following user says thank you to ChristianEhrlicher for this useful post:

    Raistlin (4th April 2008)

  6. #5
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems with korean symbols in file path

    Shouldn't QString::fromLocal8Bit() always do the trick? Because this seems to do the same: take an 8 bit string and convert it to Unicode based on the locale.

    I made a stupid mistake there, I used :

    Qt Code:
    1. QString string;
    2. string.fromLocal8Bit("something");
    To copy to clipboard, switch view to plain text mode 

    instead of

    Qt Code:
    1. QString string = QString::fromLocal8Bit("something");
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems with korean symbols in file path

    Nevermind about that last question, looking in the source code already answered my question . So fromLocal8Bit should in fact to the trick and is just retrieving the local Text Codec and performing To Unicode.

Similar Threads

  1. exception at 0x65100c40 (QtGuid4.dll)
    By sabeesh in forum Qt Programming
    Replies: 11
    Last Post: 21st December 2007, 18:10
  2. Program crashes with assert error in xcb_lock.c
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2007, 20:56
  3. KDE 3.5.0 crash while opening project
    By MarkoSan in forum KDE Forum
    Replies: 2
    Last Post: 19th October 2007, 17:21
  4. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 21:53
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 11:28

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.