Results 1 to 5 of 5

Thread: Problems with text encoding

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

    Default Problems with text encoding

    Hi guys! I have a problem with the text encoding.
    I get a string with regexp:
    Qt Code:
    1. QRegExp rxTitle("...");
    2. . . . . . . . . . . . . . .
    3. qstrTitle = rxTitle.cap(2);
    To copy to clipboard, switch view to plain text mode 
    This text contains some local characters (ru), and it's not displayed normally.
    I tried to use QString::fromLocal8Bit:
    Qt Code:
    1. . . . . . . . . . . . . . . . .
    2. qstrTitle = QString::fromLocal8Bit( qstrTitle.toAscii() );
    To copy to clipboard, switch view to plain text mode 
    No result.. I tried to use QString::toUtf8().. the same result..

    How can I display normally that text?

  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: Problems with text encoding

    Display where?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with text encoding

    If every string literal uses the same encoding, you can set it using QTextCodec::setCodecForCStrings() and QTextCodec::setCodecForTr(). If there's only one such string, make sure it's encoded in UTF-8 and use QString::fromUtf8() or use appropriate QTextCodec to convert it to QString.

  4. The following user says thank you to jacek for this useful post:

    LMZ (3rd July 2007)

  5. #4
    Join Date
    May 2007
    Posts
    46
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problems with text encoding

    2wysota: no matter.. I need to create a file with, wich name must be that string. (I try to display it on a message box)

    2jacek: thx, I'll try it..

  6. #5
    Join Date
    May 2007
    Posts
    46
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problems with text encoding

    2jacek: thank you so much! QString::fromUtf8() solved my problem. now it works perfectly!

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  4. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02
  5. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

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.