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

  • Home
  • SEARCH
  • 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 510833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:09:15+00:00 2026-05-13T07:09:15+00:00

I work on a project written for MSVCC / Windows, that I have to

  • 0

I work on a project written for MSVCC / Windows, that I have to port to GCC / Linux. The Project has its own String Class, which stores its Data in a QString from Qt. For conversion to wchar_t* there was originally this method (for Windows):

const wchar_t* String::c_str() const
{
    if (length() > 0)
    {
        return (const wchar_t*)QString::unicode();
    }
    else
    {
        return &s_nullString;
    }
}

Because unicode() returns a QChar (which is 16 Bit long), this worked under Windows as wchar_t is 16 Bit there, but now with GCC wchar_t is 32 Bit long, so that doesn’t work anymore. I’ve tried to solve that using this:

const wchar_t* String::c_str() const
{
    if ( isEmpty() )
    {
        return &s_nullString;
    }
    else
    {
        return toStdWString().c_str();
    }
}

The problem with this is, that the object doesn’t live anymore when this function returns, so this doesn’t work eiter.
I think the only way to solve this issue is to either:

  1. Don’t use String::c_str() and call .toStdString().c_str() directly
  2. Make GCC treat wchar_t as 16 bit type

Possibility one would mean several hours of needless work to me and I don’t know if possiblity 2 is even possible. My question is, how do I solve this issue best?
I’d appreciate any useful suggestion. Thank you.

  • 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-13T07:09:15+00:00Added an answer on May 13, 2026 at 7:09 am

    In my opinion, there are 2 ways :

    1. convert QString to wchar_t* when needed
    2. Let QString to store wchar_t* and return QString::unicode directly

    These two functions can convert a QString to std::string and std::wstring
    QString::toStdWString
    QString::toStdString

    To build QString as ucs4 :

    #define QT_QSTRING_UCS_4
    #include "qstring.h"
    

    This can be used in qt3(qstring.h). I can’t find the source of qt4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 292k
  • Answers 292k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Where is ContactsContract.Data class declares Content URI to store additional… May 13, 2026 at 6:15 pm
  • Editorial Team
    Editorial Team added an answer How are you displaying the error messages, with error_messages_for? I… May 13, 2026 at 6:15 pm
  • Editorial Team
    Editorial Team added an answer jQuery's map function could be used to transform an array… May 13, 2026 at 6:15 pm

Related Questions

I'm currently working on cross-platform applications and was just curious as to how other
i will be working on a project that tries to determine your position using
I'd like to work on a project, but it's a little odd. I want
The company I work for is trying to implement a release schedule and I
I've asked here a ton of questions about WSAAsyncSelect and NET.Few months ago I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.