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. [SOLVED]How To Construct a QString from unicode code point beyond u+FFFF?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How To Construct a QString from unicode code point beyond u+FFFF?

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

    Hi, I want to construct a QString from unicode code point u+1F601, and i tried this:
    @QString str(0x1F601);@

    but failed, am i doing anything wrong? how to do it correcttly?

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

      Hi,

      Unless I'm mistaken, something like

      @QString str("\U0001F601")@

      should do the job

      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
      • S Offline
        S Offline
        SuJinQt
        wrote on last edited by
        #3

        Hi SGaist,

        Thank you very much, but it did not work. I have found a way to do the job well. Just like below:

        @unsigned int ui = 0x1F601;
        QString str = QString::fromUcs4(&ui);@

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          Your "solution" is dangerous. QString::fromUcs4() requires a NUL terminated UCS4 string if the length (second) argument is not specified. You are not providing a length or a NUL here. That it does not crash is just a happy coincidence.
          @
          QString str = QString::fromUcs4(&ui, 1);
          @

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SuJinQt
            wrote on last edited by
            #5

            Hi ChrisW67,

            Yes, you are right. I forgot the important argument. Thank you!
            
            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