Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best way to construct a CString from QString and vice-versa
Forum Updated to NodeBB v4.3 + New Features

Best way to construct a CString from QString and vice-versa

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    Is this correct (assuming UNICODE)

    QString to CString: given a Qstring called qstring

    CString cstring((LPCTSTR)qstring.utf16());
    

    CString to QString: given a CString called cstring

    QString qstring((QChar *)cstring.GetBuffer());
    

    or are there better incantations?

    Thanks
    David

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #5

      Hi,

      This thread on this forum answers the same question.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #2

        Are you choosing to use CString or are you stuck with it?
        I didn't know what it was, but now that I have looked into it, I would avoid using CString if it can be helped.

        What constructors does CString provide? What data type does CString::GetBuffer() return? I am pretty sure it does not return a QChar buffer.

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #3

          For quite a long while I'm stuck to 1000's of them.

          CString documentation here: https://docs.microsoft.com/en-us/cpp/atl-mfc-shared/using-cstring?view=vs-2019, and
          https://docs.microsoft.com/en-us/cpp/atl-mfc-shared/reference/cstringt-class?view=vs-2019

          David

          1 Reply Last reply
          0
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by
            #4

            Bump! Surely someone here must know both MFC and Qt and is able to give a definitive answer?

            David

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Hi,

              This thread on this forum answers the same question.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved