Linux/QT
QString 에서 의 형 변환 (형변환)
aucd29
2013. 9. 26. 20:45
code by korone.net
QString 을 C type 형으로 변환
[code]1. char
2. char[]
3. int
4. long
QString aaa;
const char *casting;
1. aaa.ascii()[0];
2. aaa.ascii();
3. aaa.toInt();
3. aaa.toLong();
casting = aaa.ascii();
[/code]
int 형을 QString으로 변경 시키는 방법
[code]QString a;
int b = 10;
a = a.setNum(b);[/code]
char형을 QString으로 변경 시키는 방법
[code]char szFullPath[100];
strcpy(szFullPath, "world");
QString data;
QString how;
data = "Hello ";
how = data + QString(szFullPath);
[/code]
QT Manual
float -> QString
QString QString::number ( double n, char f = 'g', int prec = 6 ) [static]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Argument n is formatted according to the f format specified, which is g by default, and can be any of the following:
Format Meaning
e format as [-]9.9e[+|-]999
E format as [-]9.9E[+|-]999
f format as [-]9.9
g use e or f format, whichever is the most concise
G use E or f format, whichever is the most concise
With 'e', 'E', and 'f', prec is the number of digits after the decimal point. With 'g' and 'G', prec is the maximum number of significant digits (trailing zeroes are omitted).
[code]
double d = 12.34;
QString ds = QString( "'E' format, precision 3, gives %1" )
.arg( d, 0, 'E', 3 );
// ds == "1.234E+001"
[/code]
QString & QString::setAscii ( const char * str, int len = -1 )
void QString::setLength ( uint newLen )
[code]QString result;
int len = 0;
result.setLength( maxLen ); // allocate some space
while ( ... ) {
result[len++] = ... // fill part of the space
}
result.truncate( len ); // and get rid of the rest
[/code]
QString & QString::setNum ( long n, int base = 10 )
[code]QString string;
string = string.setNum( 1234 ); // string == "1234"[/code]
QString 을 C type 형으로 변환
[code]1. char
2. char[]
3. int
4. long
QString aaa;
const char *casting;
1. aaa.ascii()[0];
2. aaa.ascii();
3. aaa.toInt();
3. aaa.toLong();
casting = aaa.ascii();
[/code]
int 형을 QString으로 변경 시키는 방법
[code]QString a;
int b = 10;
a = a.setNum(b);[/code]
char형을 QString으로 변경 시키는 방법
[code]char szFullPath[100];
strcpy(szFullPath, "world");
QString data;
QString how;
data = "Hello ";
how = data + QString(szFullPath);
[/code]
QT Manual
float -> QString
QString QString::number ( double n, char f = 'g', int prec = 6 ) [static]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Argument n is formatted according to the f format specified, which is g by default, and can be any of the following:
Format Meaning
e format as [-]9.9e[+|-]999
E format as [-]9.9E[+|-]999
f format as [-]9.9
g use e or f format, whichever is the most concise
G use E or f format, whichever is the most concise
With 'e', 'E', and 'f', prec is the number of digits after the decimal point. With 'g' and 'G', prec is the maximum number of significant digits (trailing zeroes are omitted).
[code]
double d = 12.34;
QString ds = QString( "'E' format, precision 3, gives %1" )
.arg( d, 0, 'E', 3 );
// ds == "1.234E+001"
[/code]
QString & QString::setAscii ( const char * str, int len = -1 )
void QString::setLength ( uint newLen )
[code]QString result;
int len = 0;
result.setLength( maxLen ); // allocate some space
while ( ... ) {
result[len++] = ... // fill part of the space
}
result.truncate( len ); // and get rid of the rest
[/code]
QString & QString::setNum ( long n, int base = 10 )
[code]QString string;
string = string.setNum( 1234 ); // string == "1234"[/code]