Qt
6.x
The Qt SDK
Loading...
Searching...
No Matches
src_corelib_text_qlocale.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
5
QLocale
egyptian
(
QLocale::Arabic
,
QLocale::Egypt
);
6
QString
s1
=
egyptian
.
toString
(1.571429E+07,
'e'
);
7
QString
s2
=
egyptian
.
toString
(10);
8
9
double
d
=
egyptian
.
toDouble
(
s1
);
10
int
i
=
egyptian
.
toInt
(
s2
);
12
13
15
bool
ok
;
16
double
d
;
17
18
QLocale::setDefault
(
QLocale::C
);
// uses '.' as a decimal point
19
QLocale
cLocale
;
// default-constructed C locale
20
d
=
cLocale
.
toDouble
(
"1234,56"
, &
ok
);
// ok == false, d == 0
21
d
=
cLocale
.
toDouble
(
"1234.56"
, &
ok
);
// ok == true, d == 1234.56
22
23
QLocale::setDefault
(
QLocale::German
);
// uses ',' as a decimal point
24
QLocale
german
;
// default-constructed German locale
25
d
=
german
.
toDouble
(
"1234,56"
, &
ok
);
// ok == true, d == 1234.56
26
d
=
german
.
toDouble
(
"1234.56"
, &
ok
);
// ok == false, d == 0
27
28
QLocale::setDefault
(
QLocale::English
);
29
// Default locale now uses ',' as a group separator.
30
QString
str
=
QString
(
"%1 %L2 %L3"
).
arg
(12345).
arg
(12345).
arg
(12345, 0, 16);
31
// str == "12345 12,345 3039"
33
34
36
QLocale
korean
(
"ko"
);
37
QLocale
swiss
(
"de_CH"
);
39
40
42
bool
ok
;
43
double
d
;
44
45
QLocale
c
(
QLocale::C
);
46
d
=
c
.toDouble(
"1234.56"
, &
ok
);
// ok == true, d == 1234.56
47
d
=
c
.toDouble(
"1,234.56"
, &
ok
);
// ok == true, d == 1234.56
48
d
=
c
.toDouble(
"1234,56"
, &
ok
);
// ok == false, d == 0
49
50
QLocale
german
(
QLocale::German
);
51
d
=
german
.
toDouble
(
"1234,56"
, &
ok
);
// ok == true, d == 1234.56
52
d
=
german
.
toDouble
(
"1.234,56"
, &
ok
);
// ok == true, d == 1234.56
53
d
=
german
.
toDouble
(
"1234.56"
, &
ok
);
// ok == false, d == 0
54
55
d
=
german
.
toDouble
(
"1.234"
, &
ok
);
// ok == true, d == 1234.0
57
59
bool
ok
;
60
double
d
;
61
62
QLocale
c
(
QLocale::C
);
63
d
=
c
.toDouble(u
"1234.56"
, &
ok
);
// ok == true, d == 1234.56
64
d
=
c
.toDouble(u
"1,234.56"
, &
ok
);
// ok == true, d == 1234.56
65
d
=
c
.toDouble(u
"1234,56"
, &
ok
);
// ok == false, d == 0
66
67
QLocale
german
(
QLocale::German
);
68
d
=
german
.
toDouble
(u
"1234,56"
, &
ok
);
// ok == true, d == 1234.56
69
d
=
german
.
toDouble
(u
"1.234,56"
, &
ok
);
// ok == true, d == 1234.56
70
d
=
german
.
toDouble
(u
"1234.56"
, &
ok
);
// ok == false, d == 0
71
72
d
=
german
.
toDouble
(u
"1.234"
, &
ok
);
// ok == true, d == 1234.0
QLocale
Definition
qlocale.h:29
QLocale::toDouble
double toDouble(const QString &s, bool *ok=nullptr) const
Returns the double represented by the localized string s.
Definition
qlocale.h:950
QLocale::setDefault
static void setDefault(const QLocale &locale)
\nonreentrant
Definition
qlocale.cpp:1257
QLocale::Egypt
@ Egypt
Definition
qlocale.h:629
QLocale::toInt
int toInt(const QString &s, bool *ok=nullptr) const
Returns the int represented by the localized string s.
Definition
qlocale.h:936
QLocale::toString
QString toString(qlonglong i) const
Returns a localized string representation of i.
Definition
qlocale.cpp:1962
QLocale::C
@ C
Definition
qlocale.h:43
QLocale::Arabic
@ Arabic
Definition
qlocale.h:56
QLocale::German
@ German
Definition
qlocale.h:136
QLocale::English
@ English
Definition
qlocale.h:117
QString
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition
qstring.h:127
QString::arg
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition
qstring.cpp:8606
s1
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition
qopengles2ext.h:2707
c
const GLubyte * c
Definition
qopenglext.h:12701
ok
bool ok
[0]
Definition
src_corelib_text_qlocale.cpp:15
str
QString str
Definition
src_corelib_text_qlocale.cpp:30
s2
QString s2
Definition
src_corelib_text_qlocale.cpp:7
egyptian
QLocale egyptian(QLocale::Arabic, QLocale::Egypt)
[0]
cLocale
QLocale cLocale
Definition
src_corelib_text_qlocale.cpp:19
swiss
QLocale swiss("de_CH")
german
QLocale german
Definition
src_corelib_text_qlocale.cpp:24
d
double d
Definition
src_corelib_text_qlocale.cpp:9
c
QLocale c(QLocale::C)
i
int i
Definition
src_corelib_text_qlocale.cpp:10
korean
QLocale korean("ko")
[1]
qtbase
src
corelib
doc
snippets
code
src_corelib_text_qlocale.cpp
Generated by
1.9.7