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. QString to LPCTSTR conversion
Forum Updated to NodeBB v4.3 + New Features

QString to LPCTSTR conversion

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 12.9k 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 using win32 dll in my -QT- Qt Application.
    win32 dll has one function which takes parameter of type LPCTSTR.
    When i try to call this function from my Qt Application passing QString as parameter function is not recieveng the correct value .
    How to resolve this?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Which compiler are you using?
      How did you perform the conversion?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      -1
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        LPCTSTR = Long Pointer to a Const TCHAR STRing
        (const char*)

        Try the simple casting.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Try "QString::toWCharArray() ":http://doc.qt.nokia.com/4.7/qstring.html#toWCharArray.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            If it is a pure in parameter, you can try:

            @
            void fooSub(LPSTSTR X); // this is our function :-)

            foo()
            {
            QString text;
            if(sizeof(TCHAR) == 1)
            fooSub((LPCSTR)text.toLocal8Bit().constData()); // here you have to check, how to convert, you could also use utf8(), ...
            else
            fooSub((LPCWSTR)text.utf16());
            }
            @

            Nokia Certified Qt Specialist.
            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