Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:17:58+00:00 2026-05-22T20:17:58+00:00

Given the encoding of the project is probably Unicode (but not for sure) what

  • 0

Given the encoding of the project is probably Unicode (but not for sure) what is the best way of converting ATL::CString to QString?

What I have thought of is this:

CString c(_T("SOME_TEXT"));
//...
std::basic_string<TCHAR> intermediate((LPCTSTR)c);
QString q;

#ifdef _UNICODE 
q = QString::fromStdWString(intermediate);
#else
q = QString::fromStdString(intermediate);
#endif

Do you think that it works? Any other ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:17:59+00:00Added an answer on May 22, 2026 at 8:17 pm

    You don’t need the intermediate conversion to a std::string. The CString class can be treated as a simple C-style string; that is, an array of characters. All you have to do is cast it to an LPCTSTR.

    And once you have that, you just need to create the QString object depending on whether the characters in your CString are of type char or wchar_t. For the former, you can use one of the standard constructors for QString, and for the latter, you can use the fromWCharArray function.

    Something like the following code (untested, I don’t have Qt installed anymore):

    CString c(_T("SOME_TEXT"));
    QString q;
    
    #ifdef _UNICODE 
    q = QString::fromWCharArray((LPCTSTR)c, c.GetLength());
    #else
    q = QString((LPCTSTR)c);
    #endif
    

    Edit: As suggested in the comments, you have to disable “Treat wchar_t as a built-in type` in your project’s Properties to get the above code to link correctly in Visual Studio (source).

    For _UNICODE, I believe you could also use the fromUtf16 function:

    CString c(_T("SOME TEXT"));
    QString q = QString::fromUtf16(c.GetBuffer(), c.GetLength());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this XML: <?php $xml = <<<XML <?xml version=1.0 encoding=UTF-8 ?> <root> <project type=residential>
In Android project's strings.xml file i have following html text <?xml version=1.0 encoding=utf-8?> <resources>
I have posted a question on here previously asking similar advise, but this project
I have the following Phing configuration file: <?xml version=1.0 encoding=UTF-8?> <project name=ru.fractalizer.phpsweetpdo default=make-phar-packages basedir=..>
I have a project where I have been given a MD5 hash of a
Given a Python object of any kind, is there an easy way to get
One long term project I have is working through all the exercises of SICP.
I actually have two questions regarding the same problem but I think it is
Trying to set up a project but fail at Autowiring objects through Spring. package
In my current project, I have to create a PDF file on the fly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.