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 TCHAR and TCHAR*
Forum Updated to NodeBB v4.3 + New Features

QString to TCHAR and TCHAR*

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 6.0k 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.
  • S Offline
    S Offline
    subrat17june
    wrote on last edited by
    #1

    Hi all,
    I am using a dll, which takes a TCHAR and TCHAR*parameter in its functions.
    and my GUI elements from QT are in the form of QString.

    QT uses UTF-8 encoding which has (TCHAR as WCHAR)

    I have been working since hours to figure out a way to convert a QString value to TCHAR / TCHAR*
    have tried many forms and types..still no joy.
    please can i get a code example to convert a QString value to TCHAR / TCHAR*

    QString Value to TCHAR tValue
    and QString Value to TCHAR* rValue

    Thanks.

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

      TCHAR is just typedef of char if you use ANSI or wchar_t with UNICODE.
      if library needs ANSI:
      @
      TCHAR tc = string[0].toAscii();
      TCHAR *tc = string.toAscii().data();
      @

      UNICODE way:
      @
      static HRESULT _C2W(const char * pszChar, wchar_t **ppszwChar)
      {
      HRESULT hr = S_OK;
      unsigned int iRetVal = 0;
      iRetVal = MultiByteToWideChar(CP_ACP,0,pszChar,-1,NULL,0);
      if(iRetVal == 0){(*ppszwChar) = NULL; return E_FAIL;}
      *ppszwChar = (wchar_t *) new wchar_t[iRetVal];
      if((*ppszwChar) == NULL) return E_FAIL;
      iRetVal = MultiByteToWideChar(CP_ACP,0,pszChar,-1,*ppszwChar,iRetVal);
      return iRetVal;
      }

      TCHAR * wc = NULL;
      _C2W(string.toAscii().data(),&wc);
      TCHAR w = wc[0];
      @

      QString has function toWCharArray, but it is bugy...

      God is Real unless explicitly declared as Integer.

      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