2.1 String class The
QString class stores 16-bit Unicode values and provides a wealth of functions such as operations, queries and conversions.
(1): QString provides a binary "+" operator for combining two strings
(2): QString::append()
(3): Another function for combining strings QString::sprintf( )
(4): Qt also provides another convenient way to combine strings, using the QString::arg() function
(5): QString also provides some other ways to combine strings, including
insert()
prepend()
replace()
(6): Many times remove the blanks at both ends of a string ("\n" "\r" "\t" " ")
QString::trimmed()
QString::simplified()
2.1.2 Query string data
(1) The function QString::startsWith() judges whether a string starts with a certain string
QString str="Welcome to you!";
str.startsWith("Welcome",Qt::CaseSensitive ); //Return true
(2): function QString::endsWith()
(3): function QString::contains() to determine whether a specified string has appeared before
(4): It is also a common function to compare two strings
operatr<(const QString&) operat
<=(const QString&)
......
......
compare(const QString&,const QString&,Qt::CaseSensitivity);
2.1.3 String conversion
(1): QString provides rich conversion functions. QString::toInt() QString::toDouble(),QString::toFloat(),QString::toLong(),toLongLong
QString str="125";
bool ok;
int hex = str.toInt(&ok,16);
int dec = str.toInt(&ok,10); //ok = true,dec=125
(2): The conversion function of the character encoding provided by QString will return a const char* type version of QByteArray, that is, the constructor QByteArray (const char*) constructed QByteArray object; QByteArray supports the following conversion functions:
toAscii()
toLatin1()
toUtf8()
toLocal8Bit()
The difference between a NULL string and an empty (empty) string:
NULL: is to use the default constructor of QString or use "(const char*)0"
Empty: is a string of size 0
2.2: Container class
Note: Qt's QObject and other subclasses (such as QWidget and QDialog, etc.) cannot be stored in the container. Because QObject and other subclasses do not have copy constructors and assignment operators. A possible alternative is to store pointers to QObject and its subclasses.
2.2.1 QList class, QLinkedList class and QVector class
QList<T> maintains an array of pointers, the pointers stored in the array point to the contents of the list items stored in QList<T>
QLinkedList<T> is a linked list, which is not A contiguous block of memory holds data
QVector<T>
2.2.2 QMap class and QHash class
QMap class and QHash class have very similar functions, their only difference is:
(1): QHash has faster search speed than QMap
(2): QHash stores data items in any order , and QMap always stores data in the order of keys;
(3): QHash's key type Key must provide operator==() and a global qHash(Key) function, while QMap's key type Key must provide operator<() function
2.3 QVariant class
QVariant class is similar to the union type of C++. It can not only store many Qt type values, including QColor QBrush, etc., but also store Qt container type values.
2.4 Calculation and regular expressions
- 2.4.1 Qt 5 Common Algorithms
Qt's <QtAlgorithms> and <QtGlobal> templates provide some algorithms and functions.
qAbs(a):
qMax(b,c);
qRound(b): Return an integer closest to a floating point number
qSwap(bn,cn): Swap the values of two numbers
- 2.4.2 Basic Regular Expressions
- Qt's QRegExp is similar to the representation class of regular expressions. It is based on Perl's regular expression language and fully supports Unicode.
- The regular expression consists of:
- expressions
- quantifiers
- assertions
- (1): The simplest expression is a character
[AEIOU]: Matches all uppercase vowels
[^AEIOU]: Matches all non-vowel letters
[az]: Matches all lowercase English letters
- (2): Quantifiers indicate the number of times an expression appears
x[1,2]: Indicates that x can have at least one, at most two
[A-Za-z_]+[A-Za-z_0-9]*: It is required to start with a letter or underscore, followed by letters, numbers and underscore
which
-
- "+": Indicates that [A-Za-z] appears at least once and can appear multiple times
- "*": Indicates that [A-Za-z_0-9] can appear zero or more times
- (3) "^", "$", "\b" are all regular expression assertions
- 2.5 Controls
- 2.5.1 Button Group
- Push Button
- Tool Button
- Radio Button
- Check Box
- Command Link Button
- Button Box
- 2.5.2 Input space group
- 2.5.3 Display Control Group
- 2.5.4 Spatial interval groups
- 2.5.5 Layout Management Group
- 2.5.6 Container Group
- 2.5.7 Project View Group
- 2.5.8 Item Control Group
- 2.5.1 Button Group
L2.1 String QString: Concept Analysis
L1: Implicit sharing