⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qstring.3qt

📁 linux下GUI编程工具qt的在线连接帮助手册
💻 3QT
📖 第 1 页 / 共 5 页
字号:
.ti -1c.BI "QString & \fBsetUnicodeCodes\fR ( const ushort * unicode_as_ushorts, uint len )".br.ti -1c.BI "QString & \fBsetLatin1\fR ( const char * str, int len = -1 )".br.ti -1c.BI "int \fBcompare\fR ( const QString & s ) const".br.ti -1c.BI "int \fBlocaleAwareCompare\fR ( const QString & s ) const".br.ti -1c.BI "void \fBcompose\fR ()".br.ti -1c.BI "const char * data () const  \fI(obsolete)\fR".br.ti -1c.BI "bool \fBstartsWith\fR ( const QString & s ) const".br.ti -1c.BI "bool \fBendsWith\fR ( const QString & s ) const".br.ti -1c.BI "void \fBsetLength\fR ( uint newLen )".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "QString \fBnumber\fR ( long n, int base = 10 )".br.ti -1c.BI "QString \fBnumber\fR ( ulong n, int base = 10 )".br.ti -1c.BI "QString \fBnumber\fR ( int n, int base = 10 )".br.ti -1c.BI "QString \fBnumber\fR ( uint n, int base = 10 )".br.ti -1c.BI "QString \fBnumber\fR ( double n, char f = 'g', int prec = 6 )".br.ti -1c.BI "QString \fBfromLatin1\fR ( const char * chars, int len = -1 )".br.ti -1c.BI "QString \fBfromUtf8\fR ( const char * utf8, int len = -1 )".br.ti -1c.BI "QString \fBfromLocal8Bit\fR ( const char * local8Bit, int len = -1 )".br.ti -1c.BI "int \fBcompare\fR ( const QString & s1, const QString & s2 )".br.ti -1c.BI "int \fBlocaleAwareCompare\fR ( const QString & s1, const QString & s2 )".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "bool \fBoperator==\fR ( const QString & s1, const QString & s2 )".br.ti -1c.BI "bool \fBoperator==\fR ( const QString & s1, const char * s2 )".br.ti -1c.BI "bool \fBoperator==\fR ( const char * s1, const QString & s2 )".br.ti -1c.BI "bool \fBoperator!=\fR ( const QString & s1, const QString & s2 )".br.ti -1c.BI "bool \fBoperator!=\fR ( const QString & s1, const char * s2 )".br.ti -1c.BI "bool \fBoperator!=\fR ( const char * s1, const QString & s2 )".br.ti -1c.BI "bool \fBoperator<\fR ( const QString & s1, const char * s2 )".br.ti -1c.BI "bool \fBoperator<\fR ( const char * s1, const QString & s2 )".br.ti -1c.BI "bool \fBoperator<=\fR ( const QString & s1, const char * s2 )".br.ti -1c.BI "bool \fBoperator<=\fR ( const char * s1, const QString & s2 )".br.ti -1c.BI "bool \fBoperator>\fR ( const QString & s1, const char * s2 )".br.ti -1c.BI "bool \fBoperator>\fR ( const char * s1, const QString & s2 )".br.ti -1c.BI "bool \fBoperator>=\fR ( const QString & s1, const char * s2 )".br.ti -1c.BI "bool \fBoperator>=\fR ( const char * s1, const QString & s2 )".br.ti -1c.BI "const QString \fBoperator+\fR ( const QString & s1, const QString & s2 )".br.ti -1c.BI "const QString \fBoperator+\fR ( const QString & s1, const char * s2 )".br.ti -1c.BI "const QString \fBoperator+\fR ( const char * s1, const QString & s2 )".br.ti -1c.BI "const QString \fBoperator+\fR ( const QString & s, char c )".br.ti -1c.BI "const QString \fBoperator+\fR ( char c, const QString & s )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( QDataStream & s, const QString & str )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( QDataStream & s, QString & str )".br.in -1c.SH DESCRIPTIONThe QString class provides an abstraction of Unicode text and the classic C null-terminated char array..PPQString uses implicit sharing, which makes it very efficient and easy to use..PPIn all of the QString methods that take \fCconst char *\fR parameters, the \fCconst char *\fR is interpreted as a classic C-style 0-terminated ASCII string. It is legal for the \fCconst char *\fR parameter to be 0. If the \fCconst char *\fR is not 0-terminated, the results are undefined. Functions that copy classic C strings into a QString will not copy the terminating 0 character. The QChar array of the QString (as returned by unicode()) is generally not terminated by a null..PPA QString that has not been assigned to anything is \fInull\fR, i.e., both the length and data pointer is 0. A QString that references the empty string ("", a single '&#92;0' char) is \fIempty\fR. Both null and empty QStrings are legal parameters to the methods. Assigning \fC(const char *) 0\fR to QString gives a null QString. For convenience, QString::null is a null QString..PPNote that if you find that you are mixing usage of QCString, QString, and QByteArray, this causes lots of unnecessary copying and might indicate that the true nature of the data you are dealing with is uncertain. If the data is 0-terminated 8-bit data, use QCString; if it is unterminated (i.e. contains 0s) 8-bit data, use QByteArray; if it is text, use QString..PPLists of strings are handled by the QStringList class. You can split a string into a list of strings using QStringList::split(), and join a list of strings into a single string with an optional separator using QStringList::join(). You can obtain a list of strings from a string list that contain a particular substring or that match a particular regex using QStringList::grep()..PP\fBNote for C programmers\fR.PPDue to C++'s type system and the fact that QString is implicitly shared, QStrings may be treated like ints or other simple base types. For example:.PP.nf.br    QString boolToString( bool b ).br    {.br        QString result;.br        if ( b ).br            result = "True";.br        else.br            result = "False";.br        return result;.br    }.br.fi.PPThe variable, result, is an auto variable allocated on the stack. When return is called, because we're returning by value, The copy constructor is called and a copy of the string is returned. (No actual copying takes place thanks to the implicit sharing, see below.).PPThroughout Qt's source code you will encounter QString usages like this:.PP.nf.br    QString func( const QString& input ).br    {.br        QString output = input;.br        // process output.br        return output;.br    }.br.fi.PPThe 'copying' of input to output is almost as fast as copying a pointer because behind the scenes copying is achieved by incrementing a reference count. QString operates on a copy-on-write basis, only copying if an instance is actually changed..PPSee also QChar, QCString, QByteArray, QConstString, Implicitly and Explicitly Shared Classes, Text Related Classes and Non-GUI Classes..SS "Member Type Documentation".SH "QString::SectionFlags".TP\fCQString::SectionDefault\fR - Empty fields are counted, leading and trailing separators are not included, and the separator is compared case sensitively..TP\fCQString::SectionSkipEmpty\fR - Treat empty fields as if they don't exist, i.e. they are not considered as far as \fIstart\fR and \fIend\fR are oncerned..TP\fCQString::SectionIncludeLeadingSep\fR - Include the leading separator (if any) in the result string..TP\fCQString::SectionIncludeTrailingSep\fR - Include the trailing separator (if any) in the result string..TP\fCQString::SectionCaseInsensitiveSeps\fR - Compare the separator case-insensitively..PPAny of the last four values can be OR-ed together to form a flag..PPSee also section()..SH MEMBER FUNCTION DOCUMENTATION.SH "QString::QString ()"Constructs a null string. This is a string that has not been assigned to anything, i.e. both the length and data pointer is 0..PPSee also isNull()..SH "QString::QString ( QChar ch )"Constructs a string giving it a length of one character, assigning it the character \fIch\fR..SH "QString::QString ( const QString & s )"Constructs an implicitly shared copy of \fIs\fR. This is instantaneous, since reference counting is used..SH "QString::QString ( const QByteArray & ba )"Constructs a string that is a deep copy of \fIba\fR interpreted as a classic C string..SH "QString::QString ( const QChar * unicode, uint length )"Constructs a string that is a deep copy of the first \fIlength\fR characters in the QChar array..PPIf \fIunicode\fR and \fIlength\fR are 0, then a null string is created..PPIf only \fIunicode\fR is 0, the string is empty but has \fIlength\fR characters of space preallocated - QString expands automatically anyway, but this may speed up some cases a little. We recommend using the plain constructor and setLength() for this purpose since it will result in more readable code..PPSee also isNull() and setLength()..SH "QString::QString ( const char * str )"Constructs a string that is a deep copy of \fIstr\fR, interpreted as a classic C string..PPIf \fIstr\fR is 0, then a null string is created..PPThis is a cast constructor, but it is perfectly safe: converting a Latin1 const char* to QString preserves all the information. You can disable this constructor by defining QT_NO_CAST_ASCII when you compile your applications. You can also make QString objects by using setLatin1(), fromLatin1(), fromLocal8Bit(), and fromUtf8(). Or whatever encoding is appropriate for the 8-bit data you have..PPSee also isNull()..SH "QString::~QString ()"Destroys the string and frees the "real" string if this is the last copy of that string..SH "QString & QString::append ( const QString & str )"Appends \fIstr\fR to the string and returns a reference to the result..PP.nf.br    string = "Test";.br    string.append( "ing" );        // string == "Testing".br.fi.PPEquivalent to operator+=()..PPExample: dirview/dirview.cpp..SH "QString & QString::append ( char ch )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAppends character \fIch\fR to the string and returns a reference to the result..PPEquivalent to operator+=()..SH "QString & QString::append ( QChar ch )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAppends character \fIch\fR to the string and returns a reference to the result..PPEquivalent to operator+=()..SH "QString QString::arg ( const QString & a, int fieldwidth = 0 ) const"This function will return a string that replaces the lowest occurrence of \fC%i\fR (\fCi\fR being '1' or '2' or ... or '9') with \fIa\fR..PPThe \fIfieldwidth\fR value specifies the minimum amount of space that \fIa\fR is padded to. A positive value will produce right-aligned text, whereas a negative value will produce left-aligned text..PP.nf.br    QString firstName( "Joe" );.br    QString lastName( "Bloggs" );.br    QString fullName;.br    fullName = QString( "First name is '%1', last name is '%2'" ).br               .arg( firstName ).br               .arg( lastName );.br.br    // fullName == First name is 'Joe', last name is 'Bloggs'.br.fi.PP\fBWarning:\fR If you use arg() to construct "real" sentences like the one shown in the examples above, then this may cause problems with translation (when you use the tr() function)..PPIf there is no \fC%i\fR pattern, a warning message (qWarning()) is outputted and the text is appended at the end of the string. This is error recovery done by the function and should not occur in correct code..PPSee also QObject::tr()..SH "QString QString::arg ( long a, int fieldwidth = 0, int base = 10 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPThe \fIfieldwidth\fR value specifies the minimum amount of space that \fIa\fR is padded to. A positive value will produce a right-aligned number, whereas a negative value will produce a left-aligned number..PP\fIa\fR is expressed in base \fIbase\fR, which is 10 by default and must be between 2 and 36..PP.nf.br    QString str;.br    str = QString( "Decimal 63 is %1 in hexadecimal" ).br          .arg( 63, 0, 16 );.br    // str == "Decimal 63 is 3f in hexadecimal".br.fi.SH "QString QString::arg ( ulong a, int fieldwidth = 0, int base = 10 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR is expressed in base \fIbase\fR, which is 10 by default and must be between 2 and 36..SH "QString QString::arg ( int a, int fieldwidth = 0, int base = 10 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR is expressed in base \fIbase\fR, which is 10 by default and must be between 2 and 36..SH "QString QString::arg ( uint a, int fieldwidth = 0, int base = 10 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR is expressed in base \fIbase\fR, which is 10 by default and must be between 2 and 36..SH "QString QString::arg ( short a, int fieldwidth = 0, int base = 10 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR is expressed in base \fIbase\fR, which is 10 by default and must be between 2 and 36..SH "QString QString::arg ( ushort a, int fieldwidth = 0, int base = 10 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR is expressed in base \fIbase\fR, which is 10 by default and must be between 2 and 36..SH "QString QString::arg ( char a, int fieldwidth = 0 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP\fIa\fR is assumed to be in the Latin1 character set..SH "QString QString::arg ( QChar a, int fieldwidth = 0 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..SH "QString QString::arg ( double a, int fieldwidth = 0, char fmt = 'g', int prec = -1 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -