Qt - 字符串(二):编码转换 与 类型转换

it2022-05-13  65

(一)编码转换

QString:---------------------------------------------------------------------------------

普通成员函数:

QByteArray toAscii () constQByteArray toLatin1 () constQByteArray toLocal8Bit () constQByteArray toUtf8 () constconst ushort * utf16 () constconst QChar * unicode () constQVector<uint> toUcs4 () conststd::string toStdString () conststd::wstring toStdWString () constint toWCharArray ( wchar_t * array ) const

静态成员函数:

QString fromAscii ( const char * str, int size = -1 )QString fromLatin1 ( const char * str, int size = -1 )QString fromLocal8Bit ( const char * str, int size = -1 )QString fromUtf8 ( const char * str, int size = -1 )QString fromUtf16 ( const ushort * unicode, int size = -1 )QString fromRawData ( const QChar * unicode, int size )QString fromUcs4 ( const uint * unicode, int size = -1 )QString fromStdString ( const std::string & str )QString fromStdWString ( const std::wstring & str )QString fromWCharArray ( const wchar_t * string, int size = -1 )

 

QByteArray:---------------------------------------------------------------------------------

普通成员函数:

const char * constData () constchar * data ()const char * data () constQByteArray toBase64 () constQByteArray toHex () constQByteArray toPercentEncoding ( const QByteArray & exclude = QByteArray(), const QByteArray & include = QByteArray(), char percent = '%' ) constQByteArray & setRawData ( const char * data, uint size )

静态成员函数:

QByteArray fromBase64 ( const QByteArray & base64 )QByteArray fromHex ( const QByteArray & hexEncoded )QByteArray fromPercentEncoding ( const QByteArray & input, char percent = '%' )QByteArray fromRawData ( const char * data, int size )

 

(二)类型转换

QString:

---------------------------------------------------------------------------------

普通成员函数:

int toInt ( bool * ok = 0, int base = 10 ) constuint toUInt ( bool * ok = 0, int base = 10 ) constshort toShort ( bool * ok = 0, int base = 10 ) constushort toUShort ( bool * ok = 0, int base = 10 ) constlong toLong ( bool * ok = 0, int base = 10 ) constulong toULong ( bool * ok = 0, int base = 10 ) constqlonglong toLongLong ( bool * ok = 0, int base = 10 ) constqulonglong toULongLong ( bool * ok = 0, int base = 10 ) constdouble toDouble ( bool * ok = 0 ) constfloat toFloat ( bool * ok = 0 ) const

QString & setNum ( int n, int base = 10 )QString & setNum ( uint n, int base = 10 )QString & setNum ( short n, int base = 10 )QString & setNum ( ushort n, int base = 10 )QString & setNum ( long n, int base = 10 )QString & setNum ( ulong n, int base = 10 )QString & setNum ( qlonglong n, int base = 10 )QString & setNum ( qulonglong n, int base = 10 )QString & setNum ( double n, char format = 'g', int precision = 6 )QString & setNum ( float n, char format = 'g', int precision = 6 )

静态成员函数:

QString number ( int n, int base = 10 )QString number ( uint n, int base = 10 )QString number ( long n, int base = 10 )QString number ( ulong n, int base = 10 )QString number ( qlonglong n, int base = 10 )QString number ( qulonglong n, int base = 10 )QString number ( double n, char format = 'g', int precision = 6 )

 

QByteArray:---------------------------------------------------------------------------------

普通成员函数:

int toInt ( bool * ok = 0, int base = 10 ) constuint toUInt ( bool * ok = 0, int base = 10 ) constshort toShort ( bool * ok = 0, int base = 10 ) constushort toUShort ( bool * ok = 0, int base = 10 ) constlong toLong ( bool * ok = 0, int base = 10 ) constulong toULong ( bool * ok = 0, int base = 10 ) constqlonglong toLongLong ( bool * ok = 0, int base = 10 ) constqulonglong toULongLong ( bool * ok = 0, int base = 10 ) constdouble toDouble ( bool * ok = 0 ) constfloat toFloat ( bool * ok = 0 ) const

QByteArray & setNum ( int n, int base = 10 )QByteArray & setNum ( uint n, int base = 10 )QByteArray & setNum ( short n, int base = 10 )QByteArray & setNum ( ushort n, int base = 10 )QByteArray & setNum ( qlonglong n, int base = 10 )QByteArray & setNum ( qulonglong n, int base = 10 )QByteArray & setNum ( double n, char f = 'g', int prec = 6 )QByteArray & setNum ( float n, char f = 'g', int prec = 6 )

静态成员函数:

QByteArray number ( int n, int base = 10 )QByteArray number ( uint n, int base = 10 )QByteArray number ( qlonglong n, int base = 10 )QByteArray number ( qulonglong n, int base = 10 )QByteArray number ( double n, char f = 'g', int prec = 6 )

转载于:https://www.cnblogs.com/paullam/p/3711822.html


最新回复(0)