Results 1 to 4 of 4

Thread: Encoding problem with QTextEdit

  1. #1
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Encoding problem with QTextEdit

    I'm trying to append a string ("æææ" for example) to a QTextEdit object with .append().
    If I do this:

    print mystring
    mywidget.append("mystring")

    The output in console is "æææ", but the chars that I get in the UI ar A¡A¡A¡. What's the problem?

    The default encoding in my app is utf-8.

  2. #2
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Encoding problem with QTextEdit

    What data type is mystring? Is it a QString? Did you try using QString::fromUtf8() or setting the proper codec? If you use the QString::QString(const char *) constructor (e.g. QString mystring = "æææ";), it uses fromAscii(), which is the same as fromLatin1() unless you set a default codec. As the Qt docs state:

    QString::QString ( const char * str )

    Constructs a string initialized with the ASCII string str. The given const char pointer is converted to Unicode using the fromAscii() function.
    String QString::fromAscii ( const char * str, int size = -1 ) [static]

    Returns a QString initialized with the first size characters of the 8-bit ASCII string str.

    If size is -1 (the default), it is taken to be qstrlen(str).

    If a codec has been set using QTextCodec::setCodecForCStrings(), it is used to convert str to Unicode; otherwise this function does the same as fromLatin1().
    Last edited by victor.fernandez; 2nd September 2009 at 11:41.

  3. #3
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Encoding problem with QTextEdit

    No, it's a python utf8 string.

  4. #4
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Encoding problem with QTextEdit

    I fixed it
    mystring.decode("utf-8")

Similar Threads

  1. Problem finding text in a QTextEdit
    By Vash5556 in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2009, 14:19
  2. Css - problem with border in QTextEdit
    By Trok in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2009, 22:53
  3. i am facing a problem with QTextEdit!!!
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2008, 18:06
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 11:45

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.