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. QT and Unicode

QT and Unicode

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.8k Views
  • 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.
  • P Offline
    P Offline
    pixbyte
    wrote on last edited by
    #1

    Hello,
    I'am new to QT and I try to understand some differences between QT and old VS projects. One issue I have currently is to understand QT and its codepage. As I understand, QT is Unicode enabled. Because Iam using the VStudio 2008 compiler I assume it will be compatible with Unicode librarys from other companies. But it seems that this is wrong. I have a DLL that is compiled in unicode with VisualStudio. I can use this DLL very easy in a VisualStudio project. But If I link the DLL with a QT project I cannot use the DLL well.

    As sample:
    @ TCHAR chLicenseKey[35] = _T("KLJWVC-IXPJAP-35LAUI-AZ0G5A-2LB5KU");
    int32 res = ::Initialize(chLicenseKey, BS_ASPI_INTERNAL, BS_TRUE);@

    I tried to use this in QT but the DLL reports always an error. Because it reports a error code from the DLL header I assume that it is linked well. So I think it is a problem with the key and the string.

    So my question: Do QT use a special Unicode string that is not working with common Unicode DLLs from VisualStudio? Maybe a different UTF set? My QT source is saved in UTF-8 in case of multilanguage.
    Can I use DLLs with Unicode codepage from VisualStudio projects in QT or do I need to use Multibyte DLLs?
    Please give me some hints to solve this problem.

    Ingo

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

      Hi,

      Check that you wchar_t settings are the same between Qt and VS. IIRC the default for Qt build is "not" built-in type.

      On a side note it's Qt, QT is for Apple's QuickTime.

      Hope it helps

      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
      0
      • P Offline
        P Offline
        pixbyte
        wrote on last edited by
        #3

        Hi,
        ok, sorry for the Qt issue ;)

        So if the DLL is compiled with wchar_t as build in then it do not work with Qt?

        Ingo

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          Qt's QString internally uses UTF-16, which is the same as the 'wchar_t' type does on the Windows platform (e.g. Visual Studio). If you want to get a QString as a "native" wchar_t (UTF-16) string, you can simply use QString::utf16(). The other way around, a new QString can be constructed from a a "native" wchar_t (UTF-16) string via QString::fromUtf16().

          However be aware that Qt's functions use the "const ushort *" type, instead of "const wchar_t *" type, so you may need a typcast. This typecast is safe, because both are 16-Bit types.

          @const wchar_t test = L"Test String";
          QString myString = QString::fromUtf6((const ushort
          ) test);
          const wchar_t out = (const wchar_t) myString::utf16();@

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pixbyte
            wrote on last edited by
            #5

            Hi,
            ok, sounds all well but I stil ldo not understand all the issues. Example. As I wrote I have the code:
            @ TCHAR chLicenseKey[35] = _T("KLJWVC-IXPJAP-35LAUI-AZ0G5A-2LB5KU");
            int32 res = ::Initialize(chLicenseKey, BS_ASPI_INTERNAL, BS_TRUE);
            @
            so we have ::Initialize(TCHAR[35], int ,BOOL);
            Means the first string is a TCHAR[35] string. If I use a QString and cast it ot const wchar_t* I only get a compile error: cannot convert parameter 1 from 'const wchar_t *' to 'const TCHAR []'

            So it is still not the solution.

            Ingo

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MuldeR
              wrote on last edited by
              #6

              TCHAR is not a specific type. TCHAR is a macro, defined in <tchar.h>. It is part of Microsoft's way to support building the same code with Unicode (UTF-16) strings or with ANSI strings.

              Depending on your project configuration, TCHAR will either expand to "wchar_t" (Unicode) or to "char" (ANSI). Probably the function you are calling expects the type "wchar_t", but your project configuration is set to ANSI, i.e. TCHAR will expand to "char". The same way the _T() macro will either expand to an L-prefix (and thus create a Unicode string literal) or just do nothing at all (and thus create an ANSI string literal).

              If you explicitly want to use "wchar_t" (or "char"), then you should be using those directly rather than using the TCHAR macro. Using TCHAR is a good idea, only if you want to use the T-foobar macros all the way...

              (BTW: All those considerations are not Qt-specific or Qt-related at all)

              --

              See also:

              • http://msdn.microsoft.com/en-us/library/se784sk6.aspx
              • http://msdn.microsoft.com/en-us/library/tsbaswba.aspx

              My OpenSource software at: http://muldersoft.com/

              Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

              Go visit the coop: http://youtu.be/Jay...

              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