Results 1 to 6 of 6

Thread: Qstring conversion containing japanese character's to const char *.

  1. #1
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Qstring conversion containing japanese character's to const char *.

    Hi ,
    I store the Japanese character in QString.
    Now i want to convert QString to const Char * .
    When i do so using qPrintable my const char * pointer points to some garbage value like "??".
    How to convert QString to const char * which contains Japanese charater.

    Thanks.

  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: Qstring conversion containing japanese character's to const char *.

    qPrintable() uses latin1 encoding. Japanese characters won't fit in there. You need to use proper encoding.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Qstring conversion containing japanese character's to const char *.

    Could you please suggest some code for the correct encoding .

  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: Qstring conversion containing japanese character's to const char *.

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Qstring conversion containing japanese character's to const char *.

    I tried using QTextCodec .But it didn't worked

    QString stringName; //Normal English String to be converted into Japanese .

    QString strTitle=QApplication::translate("Window", stringName.toUtf8().data() , 0 , QCoreApplication::UnicodeUTF8 ); //Returns Japanese Charater properly

    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QByteArray byteString = codec->fromUnicode(strTitle);


    I want const char * pointer pointing to this japanese string so i converted it to byteArray.
    But here byteString doesn't contain proper japanese character .


    I am using UTF-8 encoding as it solve all encoding problems in all languages of the world.

    Let me know about my approach.
    Thanks.

  6. #6
    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: Qstring conversion containing japanese character's to const char *.

    You can't put utf-8 encoded strings in char*. I suggest you first learn what encoding are, why we use them and what each of them looks like before you try to solve your problem. Don't just blindly try things you don't understand.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to convert QString to const char*
    By fulin in forum Newbie
    Replies: 7
    Last Post: 9th May 2010, 23:25
  2. Char* <-> QString implicit conversion
    By kingfinn in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2010, 08:26
  3. char* to QString: conversion
    By abghosh in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2010, 09:32
  4. conversion from QString to const uint8 *
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2007, 13:14
  5. QString to const char
    By TheRonin in forum Newbie
    Replies: 2
    Last Post: 12th February 2007, 14:43

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.