Results 1 to 13 of 13

Thread: Unicode strings int Qt 4.2.1

  1. #1
    Join Date
    Aug 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Unicode strings int Qt 4.2.1

    Hi everyone!

    I'm editing source code with Eclipse with UTF-8 character set to all files in project. But when I try to wrote Cyrillic characters directly in source code, in execution I got to unpleasant symbols, not what I wrote.

    Where I'm was wrong?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unicode strings int Qt 4.2.1

    Use QTextCodec::setCodecForCStrings to set a codec before using any QStrings.
    This can be done in main.cpp, right after instantiating the QApplication object.
    Example:
    Qt Code:
    1. QTextCodec::setCodecForCStrings(QTextCodec::codecForName("ISO-8859-5"));
    To copy to clipboard, switch view to plain text mode 
    This is just an example to show you how it's done. I am not sure if that is the standard Cyrillic encoding name.

    Regards

  3. The following user says thank you to marcel for this useful post:

    mkrentovskiy (6th August 2007)

  4. #3
    Join Date
    Aug 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Unicode strings int Qt 4.2.1

    Yes, it's worked. I use "UTF-8" as param. Thank's!!! : )))

  5. #4
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unicode strings int Qt 4.2.1

    still not working for me....I'm trying to add unicode chars and this is the error I get in visual c++


    warning C4566: character represented by universal-character-name '\u03C3' cannot be represented in the current code page (1252)

    I'm trying to add the chars sigma and mu to the status bar.

    any help would be appreciated

    thanks,

    Jonathan

  6. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unicode strings int Qt 4.2.1

    Use and UTF-8 codec for C strings, as shown above.
    Do not give the unicode codes for the two chars.
    Instead write the char directly in code:
    Qt Code:
    1. QString sigma = "σ";
    To copy to clipboard, switch view to plain text mode 
    Next, if you set the codec correctly, you can set this string to the status bar.

    If you really want to use Unicode codes, than you can try QString::fromUtf16( or one of the other conversion functions )

    Regards

  7. #6
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unicode strings int Qt 4.2.1

    still getting same here when I'm compiling.....do I need to change the format the document is saved as?

    right now it is set to: unicode - codepage 1200

    I've also tried unicode (UTF-8 with signature) code page 65001

    thanks for your help!

  8. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unicode strings int Qt 4.2.1

    Yes, change the encoding to UTF-8
    Are you using Eclipse also?

  9. #8
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unicode strings int Qt 4.2.1

    yeah, changed the encoding to utf-8 and using visual c++ 2005 express edition

  10. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unicode strings int Qt 4.2.1

    Well, is it working?

  11. #10
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unicode strings int Qt 4.2.1

    no dice so far, and I've tried a bunch of different file formats.....is this a compiler thing maybe?

  12. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unicode strings int Qt 4.2.1

    Qt Code:
    1. QChar chr[] = {0X03c3};
    2. QString xxx = QString::fromRawData(chr, 1);
    To copy to clipboard, switch view to plain text mode 

    EDIT: don't forget to set the unicode codec in main.cpp.

    regards
    Last edited by marcel; 6th August 2007 at 16:42.

  13. The following user says thank you to marcel for this useful post:

    JonathanForQT4 (6th August 2007)

  14. #12
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unicode strings int Qt 4.2.1

    working like a charm, many thanks!

  15. #13
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unicode strings int Qt 4.2.1

    I use Eclipse IDE for C/C++ & QT integration plug-in , but I'm not write Unicode ?
    How to resolve ? Thank every body.
    Example: I write : "Chà o tất cả các bạn!" but It show in program: "Chà o t?t c? các b?n"
    Nguyá»…n LÆ°u VÅ© - Http://nguyenluuvu.com

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.