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 125 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.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on 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
    • 8Observer88 Offline
      8Observer88 Offline
      8Observer8
      wrote on last edited by 8Observer8
      #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
      • 8Observer88 8Observer8 has marked this topic as solved on

      • Login

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