Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Print a degrees symbol
Forum Updated to NodeBB v4.3 + New Features

Print a degrees symbol

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 4 Posters 9.3k 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.
  • K Offline
    K Offline
    kgregory
    wrote on last edited by kgregory
    #1

    I'm using QStream and QTextStream to format text that is displayed on a QML Text object in my app. I want to print a degrees symbol (°). How can I do this?

    I tried putting the character in my string literal, which worked except that it also printed an "A" with an accent.

    1 Reply Last reply
    1
    • V Offline
      V Offline
      vivekyuvan
      wrote on last edited by
      #2

      @kgregory use this symbol before your Text "\xB0"

      EX : setText("\xB0 C");
      EX : this->ui->Temp_label_unit->setText("\xB0 C");

      output will be like this °C

      S 1 Reply Last reply
      3
      • J Offline
        J Offline
        jaatvishal854
        wrote on last edited by jaatvishal854
        #3

        use Below for printing °C.

        qsTr("\u2103")

        output will be like this °C

        1 Reply Last reply
        0
        • V vivekyuvan

          @kgregory use this symbol before your Text "\xB0"

          EX : setText("\xB0 C");
          EX : this->ui->Temp_label_unit->setText("\xB0 C");

          output will be like this °C

          S Offline
          S Offline
          Simondo
          wrote on last edited by
          #4

          @vivekyuvan This worked with my previous ancient setup (VS2007, QT4.5), but I have found when upgrading to my current setup (VS2019, QT6.5.2) this doesn't work any more and just puts a question mark in a black diamond instead of showing the appropriate character.

          What has worked for me with QT6.5.2/VS2019 is
          [ui-element]->setText( QString::fromLocal8Bit( "\xB0 C") );

          or

          [ui-element]->setText(QString::fromUtf8( "\xC2\xB0 C"));

          I think the latter may be better as I'm guessing as what the first option translates may depend on the codepage of your locale.

          1 Reply Last reply
          1

          • Login

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