Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    3
    5
    1647
    Loading More Posts
    • 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
      SuJinQt last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • S
          SuJinQt last edited by

          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 Reply Quote 0
          • C
            ChrisW67 last edited by

            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 Reply Quote 0
            • S
              SuJinQt last edited by

              Hi ChrisW67,

              Yes, you are right. I forgot the important argument. Thank you!
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post