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 change QString(x***....) to Chinese ?

How to change QString(x***....) to Chinese ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 576 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1
    foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
        QString name = storage.name();
        // storage.fileSystemType() = "vfat"; name is Chinese;
        // name = "\xc0\xcfë\xcc\xd2U\xc5\xcc";
    }
    

    https://github.com/sonichy

    B 1 Reply Last reply
    0
    • CybeXC Offline
      CybeXC Offline
      CybeX
      wrote on last edited by
      #2

      think this could help you: https://doc.qt.io/qt-5/qtlinguist-hellotr-example.html and this https://doc.qt.io/qt-5/i18n-source-translation.html

      you will need to load your desired locale and use tr() for all your translated strings.

      Hope it helps.

      1 Reply Last reply
      2
      • sonichyS sonichy
        foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
            QString name = storage.name();
            // storage.fileSystemType() = "vfat"; name is Chinese;
            // name = "\xc0\xcfë\xcc\xd2U\xc5\xcc";
        }
        
        B Offline
        B Offline
        Bonnie
        wrote on last edited by
        #3

        @sonichy
        You should know what text codec is it, then use QTextCodec functions to convert (in this case I think it is GBK).
        Or you can simply try QString::fromLocal8Bit if the system locale codec is GBK.
        But why there is a ë in a Chinese string? I'm not sure it can be displayed.

        sonichyS 1 Reply Last reply
        0
        • B Bonnie

          @sonichy
          You should know what text codec is it, then use QTextCodec functions to convert (in this case I think it is GBK).
          Or you can simply try QString::fromLocal8Bit if the system locale codec is GBK.
          But why there is a ë in a Chinese string? I'm not sure it can be displayed.

          sonichyS Offline
          sonichyS Offline
          sonichy
          wrote on last edited by
          #4

          @Bonnie said in How to change QString(x***....) to Chinese ?:

          QString::fromLocal8Bit

          QString name = QString::fromLocal8Bit(storage.name());
          

          no matching function for call to ‘QString::fromLocal8Bit(QString)’

          https://github.com/sonichy

          B 1 Reply Last reply
          0
          • sonichyS sonichy

            @Bonnie said in How to change QString(x***....) to Chinese ?:

            QString::fromLocal8Bit

            QString name = QString::fromLocal8Bit(storage.name());
            

            no matching function for call to ‘QString::fromLocal8Bit(QString)’

            B Offline
            B Offline
            Bonnie
            wrote on last edited by Bonnie
            #5

            @sonichy
            yes, the conversion should be from a byte array or char*.
            If you test with

            QString::fromLocal8Bit("\xc0\xcfë\xcc\xd2U\xc5\xcc")
            

            with GBK as the system locale, you'll succesfully get a Chinese string except that "ë".
            But I'm not sure what encoding is your QString using.
            Where do you get that output of "\xc0\xcfë\xcc\xd2U\xc5\xcc"?
            From qDebug() or other?
            And what is the size of this QString? 8 or 5?
            Also the result from QStorageInfo::name() should usually already be unicode and don't need to be converted.
            What's the output of qDebug() << storage.name() then?

            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