Results 1 to 7 of 7

Thread: Make QTextStream write with UTF8 enabled?

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Make QTextStream write with UTF8 enabled?

    This is the code:
    Qt Code:
    1. QFile file(home16);
    2. if (!file.open(QIODevice::WriteOnly)) {
    3. cerr << "Cannot open file" << home16 << " for writing. The reason: "
    4. << qPrintable(file.errorString()) << endl;
    5. cout << "Try again."; system("echo "" > /home/$USER/.config/WallpaperChanger/Checks/text_to_buton");
    6. }
    7. QTextStream out(&file);
    8. out << realpath;
    9. file.close();
    To copy to clipboard, switch view to plain text mode 
    where `home16` is a file's path and `realpath` is a char* which contains greek characters, How will i write this character to the file `home16` without the greek characters to turn to "chinese"? Thx in advance!
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Make QTextStream write with UTF8 enabled?

    Quote Originally Posted by hakermania View Post
    How will i write this character to the file `home16` without the greek characters to turn to "chinese"? Thx in advance!
    I don't think I understand this question. You say you've got "greek characters" in this char* sequence and want to turn them into "chinese characters"? What kind of translation are you expecting this to be?

    Do you know what code-set you're trying to translate from and to? AFAIK the codes for greek and chinese characters aren't in the same area when using Unicode (UTF8).

  3. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Make QTextStream write with UTF8 enabled?

    No, my friend, my question is clear. i want the greek characters (the char* realpath) to be written to the file `home16` WITHOUT to turn into "chinese" (I mean weird symbols etc)
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  4. #4
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Make QTextStream write with UTF8 enabled?

    Quote Originally Posted by hakermania View Post
    No, my friend, my question is clear. i want the greek characters (the char* realpath) to be written to the file `home16` WITHOUT to turn into "chinese" (I mean weird symbols etc)
    Well, if it was clear I wouldn't be explaining what I didn't understand...but oh well.

    Have you tried converting your byte sequence into a QString using the appropriate ::from XXX function? For instance, if your byte sequence is in UTF-8 then my guess would be that you'd get better results with:
    Qt Code:
    1. out << QString::fromUTF8(realpath);
    To copy to clipboard, switch view to plain text mode 

    Also, not all programs are going to display your text output correctly. You'll need something specifically able to deal with Unicode and have the right font loaded, etc... It is possible that you've already gotten correct output but are looking at it with something not smart enough to read it correctly.

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

    hakermania (28th December 2010)

  6. #5
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Make QTextStream write with UTF8 enabled?

    Thank you, this worked
    And a note: LINUX are not as WINDOWS, they have programs that CAN read Unicode Characters HAHAHA
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  7. #6
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Make QTextStream write with UTF8 enabled?

    Quote Originally Posted by hakermania View Post
    Thank you, this worked
    And a note: LINUX are not as WINDOWS, they have programs that CAN read Unicode Characters HAHAHA
    That actually used to be fairly difficult to get working correctly. Glad to see that it's improved.

  8. #7
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Make QTextStream write with UTF8 enabled?

    If you are talking about a GUI program that could read unicode, you're right, but as long as I use Linux, nano and vim read unicode perfectly.
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

Similar Threads

  1. Replies: 2
    Last Post: 2nd November 2010, 05:15
  2. Replies: 4
    Last Post: 9th August 2009, 01:04
  3. How to write to a TCPSocket with a QTextStream?
    By Denarius in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2009, 12:28
  4. Read/Write from QTextStream
    By tonde in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2008, 16:51
  5. QTableWidgetItem not enabled
    By Raccoon29 in forum Newbie
    Replies: 2
    Last Post: 21st March 2008, 18:39

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.