Results 1 to 2 of 2

Thread: Convert QString to TCHAR

  1. #1
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Convert QString to TCHAR

    Hi,

    How can I convert QString to TCHAR? My codes below does not work.

    Qt Code:
    1. QString userName = "John Doe";
    2.  
    3. TCHAR nameBuffer[256];
    4. memset(nameBuffer, 0, sizeof(nameBuffer));
    5.  
    6. #if UNICODE
    7. _tcscpy_s(nameBuffer, _countof(nameBuffer), userName.toUtf8());
    8. #else
    9. _tcscpy_s(nameBuffer, _countof(nameBuffer), userName.toLocal8Bit());
    10. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Convert QString to TCHAR

    Use QString::utf16 for unicode. There is no need to copy it unless you need to alter it. If you do need to alter it, you can use QString::toWCharArray.

Similar Threads

  1. Retrieving QString from TCHAR
    By GTBuilder in forum Newbie
    Replies: 6
    Last Post: 28th March 2008, 06:43
  2. convert QString to int
    By mattia in forum Newbie
    Replies: 2
    Last Post: 4th January 2008, 09:10
  3. how to convert int to QString?
    By phillip_Qt in forum Newbie
    Replies: 2
    Last Post: 5th October 2007, 08:07
  4. How to convert Int to QString in QT4?
    By drake1983 in forum Newbie
    Replies: 2
    Last Post: 11th March 2007, 06:58
  5. How to convert from QString to quint16 ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 31st March 2006, 09:00

Tags for this Thread

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.