Results 1 to 2 of 2

Thread: Returning hex value of utf8 string

  1. #1
    Join Date
    Sep 2017
    Location
    Tehran/8Par
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Returning hex value of utf8 string

    I wrote a very simple test code,which receive a utf8 string from QLineEdit and display it in messagebox:

    Qt Code:
    1. QString txtString = ui->lineEdit->text();
    2. QString scndString = txtString.toUtf8();
    3. QMessageBox msgBox;
    4.  
    5. msgBox.setText(scndString);
    6. msgBox.exec();
    To copy to clipboard, switch view to plain text mode 

    Know I want to display utf8 hex value of string instead of string itself, but when I try to do this :

    Qt Code:
    1. QString txtString = ui->lineEdit->text();
    2. QString scndString = txtString.toLatin1.toutf8.toHex();
    3. QMessageBox msgBox;
    4.  
    5. msgBox.setText(scndString);
    6. msgBox.exec();
    To copy to clipboard, switch view to plain text mode 

    I received this message:
    error: 'txtString.QString::toLatin1' does not have class type QString scndString = txtString.toLatin1.toutf8.toHex();

  2. #2
    Join Date
    Jul 2017
    Posts
    37
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Returning hex value of utf8 string

    You don't convert it to Latin-1 and then to UTF-8. That doesn't work. You convert the QString (which is UTF-16) directly to UTF-8.
    Qt Code:
    1. txtString.toUtf8().toHex()
    To copy to clipboard, switch view to plain text mode 
    You need the parentheses because toUtf8 is a method (a function which is a member of a class), not a variable. I haven't used QByteArray, but hopefully that'll work.

Similar Threads

  1. Replies: 13
    Last Post: 27th August 2014, 12:06
  2. Replies: 2
    Last Post: 11th July 2012, 01:18
  3. Reading string in Utf8 from binary file
    By iddqd in forum Newbie
    Replies: 3
    Last Post: 19th July 2010, 07:16
  4. UTF8 and ByteOrderMark (BOM)
    By SidGBF in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2008, 23:25
  5. returning a string
    By mickey in forum General Programming
    Replies: 2
    Last Post: 3rd February 2008, 20:41

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.