×
Namespaces

Variants
Actions
(Difference between revisions)

Currency symbols in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetadata)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
Line 24: Line 24:
 
A fairly common case of using special characters are currency symbols. The general advice is that you should not include these symbols in your code, as then your editor, compiler, platform and target device have to align up. Usually the suggestion is to use the tr() translation mechanism, but for a simple task like currency symbol there is a simpler solution. Here is an example using an EUR sign in a QLabel:
 
A fairly common case of using special characters are currency symbols. The general advice is that you should not include these symbols in your code, as then your editor, compiler, platform and target device have to align up. Usually the suggestion is to use the tr() translation mechanism, but for a simple task like currency symbol there is a simpler solution. Here is an example using an EUR sign in a QLabel:
  
<code cpp>
+
<code cpp-qt>
 
#define EUR QChar(8364)
 
#define EUR QChar(8364)
 
#define GBP QChar(163)
 
#define GBP QChar(163)

Latest revision as of 04:16, 11 October 2012

Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: achipa (31 Dec 2010)
Last edited: hamishwillee (11 Oct 2012)

A fairly common case of using special characters are currency symbols. The general advice is that you should not include these symbols in your code, as then your editor, compiler, platform and target device have to align up. Usually the suggestion is to use the tr() translation mechanism, but for a simple task like currency symbol there is a simpler solution. Here is an example using an EUR sign in a QLabel:

#define EUR QChar(8364)
#define GBP QChar(163)
#define JPY QChar(165)
 
QLabel label = new QLabel();
label->setText(QString("Currency is %1").arg(EUR));

This way the encoding of the source files is irrelevant, as Qt's QString will interpret the utf characters, not the editor or platform.

This page was last modified on 11 October 2012, at 04:16.
64 page views in the last 30 days.