Results 1 to 5 of 5

Thread: ° character

  1. #1
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default ° character

    Hi all

    In a display widget such as a QLabel, I'd like to introduce the character ° (for degree)
    For instance :

    Qt Code:
    1. QLabel *AngleLabel = new QLabel("Angle (°)")
    To copy to clipboard, switch view to plain text mode 

    Although the ° character will ouput correctly on Windows, it gives strange things instead on Linux.

    Is there some special coding that should be set somewhere to get it output correctly ?

    Thanks

  2. #2
    Join Date
    Apr 2009
    Posts
    18
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: ° character

    try this

    Qt Code:
    1. QLabel *AngleLabel = new QLabel(QString::fromUtf8("Angle (°)"))
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: ° character

    QString by default assumes a conversion from C Strings using a local 8 bit encoding which is different for different systems. Therefore what works on Windows will not work on Linux. You need to explicitely set what encoding should be used either by QTextCodec::setCodecForCStrings() or by explicitely saying which codec to use for a particular conversion, for instance QString::fromUtf8().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ° character

    same problem came to me.... but on windows too.

    the solution is

    Qt Code:
    1. QChar ch(0xNN); //replace NN with the unicode charecter code for the degree symbol
    2. QString s="Angle (";
    3. s.append(ch);
    4. s.append(")");
    5. QLabel *AngleLabel = new QLabel(s);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Dec 2008
    Location
    Paris, France
    Posts
    34
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ° character

    Great, it worked.

    Thanks for your kind and quick answers

Similar Threads

  1. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  2. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 11:25
  3. Getting some unusual character
    By Abc in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2008, 06:28
  4. Special Character Handling
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 22:58
  5. Character from argument disappears
    By Pepe in forum Qt Programming
    Replies: 13
    Last Post: 19th June 2007, 23:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.