Results 1 to 4 of 4

Thread: How to convert wchar_t* into char*??

  1. #1
    Join Date
    Mar 2006
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to convert wchar_t* into char*??

    Hi,

    I want to convert wchar_t* into char*. Can anybody tell me how to achieve this without information loss??

    Thanks in advance.

    Shail.

  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: How to convert wchar_t* into char*??

    I think you'd have to convert it to std::wstring and then use QString::fromStdWString() to convert to a QString and then you can convert it using QString::unicode() or using qPrintable() (be ready for a data loss in this situation, as your local encoding may not support all unicode characters).

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

    shailesh (22nd June 2006)

  4. #3
    Join Date
    Mar 2006
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to convert wchar_t* into char*??

    Thanks wysota,

    But again QString.unicode will give me const QChar*. QChar is of 2 bytesin Qt. I want pure char* as i want to write it into file in UTF16 encoding.

    Actually i have QString. I want to convert it in UTF16 using QString.utf16() and then I want to write it into file. But as u know QFile does not allow us to write unicode directly. So first we have to convert it into char* and then we can write it to file.

    Can u give me suggestions for this??

    Again thanksin advance.

    Shail.

  5. #4
    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: How to convert wchar_t* into char*??

    Then use QTextCodec.

Similar Threads

  1. Convert QPixmap to QByteArray ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2014, 08:23
  2. How to convert from QString to string ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 1st December 2010, 01:50
  3. How to convert from QString to quint16 ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 31st March 2006, 09:00
  4. convert iterator
    By mickey in forum General Programming
    Replies: 8
    Last Post: 20th March 2006, 21:59
  5. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17

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.