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. How to convert LPTSTR to QString or QByteArray

How to convert LPTSTR to QString or QByteArray

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 13.3k Views 1 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hi All

    I am storing some value in LPTSTR which now i want to send to my AT application.
    So can anyone tell me how to convert this to QString or QByteArray.

    BR
    Rajveer

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxim.prishchepa
      wrote on last edited by
      #2

      try:
      @LPTSTR myStr;
      ...
      QString convertedStr = QString::fromLocal8Bit((const char *)myStr);@

      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #3

        if you use Unicode charset LPTSTR will be typedef of LPWSTR, in this case use
        @QString QString::fromWCharArray ( const wchar_t * string, int size = -1 )@

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Indrajeet
          wrote on last edited by
          #4

          Hi

          If i do as shown below I am receiving only one character in QString.
          QString convertedStr = QString::fromLocal8Bit((const char *)myStr);

          How to get the full data.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cincirin
            wrote on last edited by
            #5

            As "AcerExtensa" I think you use unicode character set (in latest VC versions this is the default)
            So you could try something like this:
            @
            #ifdef UNICODE
            QString convertedStr = QString::fromWCharArray(yourLPTSTR)
            #else
            QString convertedStr = QString::fromLocal8Bit(yourLPTSTR)
            #endif
            @

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maxim.prishchepa
              wrote on last edited by
              #6

              [quote author="cincirin" date="1326884757"]As "AcerExtensa" I think you use unicode character set (in latest VC versions this is the default)
              So you could try something like this:
              @
              #ifdef UNICODE
              QString convertedStr = QString::fromWCharArray(yourLPTSTR)
              #else
              QString convertedStr = QString::fromLocal8Bit(yourLPTSTR)
              #endif
              @[/quote]

              and set second param - datasize for your string

              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

              1 Reply Last reply
              0

              • Login

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