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 equivalent of JavaScript .charCodeAt()

Qt equivalent of JavaScript .charCodeAt()

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 129 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.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 9 Sept 2023, 16:10 last edited by
    #1

    How to translate this code from JS to Qt:

    const str = "你好";
    const code = str.charCodeAt(0);
    console.log(code); // output: 20320
    
    1 Reply Last reply
    0
    • 8 Offline
      8 Offline
      8Observer8
      wrote on 9 Sept 2023, 16:44 last edited by 8Observer8 9 Sept 2023, 16:46
      #2

      Solution:

          QString str = "你好";
          int code = str[0].unicode();
      
          QHBoxLayout *hbox = new QHBoxLayout(this);
          QLabel *lbl = new QLabel(QString::number(code));
          hbox->addWidget(lbl);
          setLayout(hbox);
      
      1 Reply Last reply
      1
      • 8 8Observer8 has marked this topic as solved on 9 Sept 2023, 16:44

      1/2

      9 Sept 2023, 16:10

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved