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. Unicode Problem..
Forum Updated to NodeBB v4.3 + New Features

Unicode Problem..

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 5.5k 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.
  • A Offline
    A Offline
    ahura_24
    wrote on last edited by
    #1

    hi everybody. i want use unicode in qt Creator my code is

    @
    #include <QtGui>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QPushButton btn( QString::fromUtf8("بستن") ); // unicode
    btn.show();
    
    return app.exec&#40;&#41;;
    

    }
    @

    its right in qt creator but when i run project this unicode will be shown ambigues font !

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Does the default font that is being used to display the text on your OS when you run the app support those characters?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

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

        yes . my windows is 7 64bit and set to region and language -> language for non-unicode program to this language.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on last edited by
          #4

          Are you sure the following code
          @
          char str[] = "بستن";
          @
          will get utf8 encoded bytes of "بستن"?


          First, your source code should be saved as utf8 with BOM.

          Then add following lines to your souce code.(If you are using MSVC2010)
          @
          #ifdef Q_CC_MSVC
          #pragma execution_character_set("UTF-8")
          #endif
          @

          If you are using MinGW, nothing special need to do.(with or without BOM)

          If you are using MSVC2005 or MSVC2008, I don't know how to do.

          If you are using MSVC2003, save source code as utf8 without BOM should works.

          ....

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ahura_24
            wrote on last edited by
            #5

            i use visual 2008 pro sp1. yes im sure encoded bytes of "بستن". i try to use mingw but i cant download it and i dont know how i must to use mingw or set qt option to use it ! if you know please help me.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dbzhang800
              wrote on last edited by
              #6

              Hi,

              IMO, this is pure C++ problem.

              If you are not sure that the execution_character_set of your compile environment is utf8, you can give a try to

              @
              char str[] = "\xd8\xa8\xd8\xb3\xd8\xaa\xd9\x86"; //I don't know whether it is the right utf8 bytes ;-)
              QString::fromUtf8(str);
              @

              instead of
              @
              char str[] = "بستن";
              QString::fromUtf8(str);
              @

              The formal will works in all the compilers, while the latter will depend on which compiler you choose.

              I do not know how to make the latter works under MSVC2005 or MSVC2008. In fact, I can not achieve this using Chinese-Version-of-MSVC2008. that's why MSVC2010 support

              @
              #pragma execution_character_set
              @

              In addition, if your compile support C++11, you can write

              @
              char str[] = u8"بستن";
              QString::fromUtf8(str);
              @

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

                Maybe:

                @QPushButton btn( QString:::fromWCharArray(L"بستن") );@
                @QPushButton btn( QString::fromUtf16((const ushort*) L"بستن") );@

                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
                • D Offline
                  D Offline
                  dbzhang800
                  wrote on last edited by
                  #8

                  Yes, wchar_t is good option before compilers providing full support for char16_t and char32_t .

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dbzhang800
                    wrote on last edited by
                    #9

                    If fact, QStringLiteral can be used under Qt5.

                    @
                    QString str = QStringLiteral("بستن");
                    @

                    depend on which compiler used, it will use

                    @
                    char16_t* & u"بستن"
                    @
                    or
                    @
                    wchar_t* & L"بستن"
                    @
                    or
                    @
                    ushort*
                    @
                    or
                    @
                    char*
                    @

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      ahura_24
                      wrote on last edited by
                      #10

                      tnx every body for your help

                      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