Qt tool and java encryption and decryption Tool

Source: Internet
Author: User
Tags format definition

Qt tool and java encryption and decryption Tool
1. The following operators are available for string-type 1.1 operator strings. (1) QString provides a binary "+" operator to combine two strings, and provides a "+ =" operator to append a string to the end of another string. For example: QString str1 = "Welcome"; str1 = str1 + "to you! "; // Str1 =" Welcome to you! "QString str2 =" Hello, "; str2 + =" World! "; // Str2 =" Hello, World! "(2) QString: append () function has the same function as the" + = "operator, so that another string can be appended to the end of a string, for example: QString str1 = "Welcome"; QString str2 = "to"; str1.append (str2); // str1 = "Welcome to" str1.append ("you! "); // Str1 =" Welcome to you! "(3) another function that combines strings is QString: sprintf (). This function supports the same format definition as the sprintf () function in the C ++ library. Example: QString str; str. sprintf ("% s", "Welcome"); // str = "Welcome" str. sprintf ("% s", "to you! "); // Str =" to you! "Str. sprintf (" % s "," Welcome "," to you! "); // Str =" Welcome to you! "(4) Qt also provides another convenient string combination method. Using the QString: arg () function, the overload of this function can process many data types. In addition, some heavy loads have additional parameters to control the field width, number base, or floating point precision. Generally, compared with the function QString: sprintf (), the function QString: arg () is a good solution, because of its type security, it fully supports Unicode, the order of "% n" parameters can be changed. Example: QString str; str = QString ("% 1 was born in % 2. "). arg ("John "). arg (1982); // str = "John was born in 1982. "(5) QString also provides some other string combination methods, including the following. ① Insert () function: insert another string at a specific position of the original string; ② prepend () function: insert another string at the beginning of the original string; ③ replace () function: use the specified string to replace some characters in the original string. (6) many times, the blank spaces at both ends of a string are removed (the blank characters include the carriage return character "\ n", the line feed character "\ r", The Tab character "\ t", and the space character) very useful, for example, when obtaining the account entered by the user. ① QString: trimmed () function: removes white spaces at both ends of a string; ② QString: simplified () function: removes white spaces at both ends of a string, use a single space character "" to replace the blank characters in the string. Example: QString str = "Welcome \ t to \ n you! "; Str = str. trimmed (); // str =" Welcome \ t to \ n you!"
1.2 query string data (1) function QString: startsWith () judge whether a string starts with a string. This function has two parameters. The first parameter specifies a string, and the second parameter specifies whether it is case sensitive (by default, it is case sensitive). For example: QString str = "Welcome to you! "; Str. startsWith ("Welcome", Qt: CaseSensitive); // return true; str. startsWith ("you", Qt: CaseSensitive); // return false; (2) function QString: endsWith () similar to QString: startsWith (), this function determines whether a string ends with a string. (3) function QString: contains (): determines whether a specified string has appeared. For example, QString str = "Welcome to you! "; Str. contains (" Welcome ", Qt: CaseSensitive); // returns true (4) to compare two strings. QString provides multiple comparison methods. ① Operator <(const QString &): Compares whether a string is smaller than another string. If yes, true is returned; ② operator <= (const QString &): compares whether a string is less than or equal to another string. If yes, true is returned; ③ operator = (const QString &): Compares two strings for equality. If yes, true is returned; ④ operator >=( const QString &): Compares whether a string is greater than or equal to another string. If yes, true is returned; ⑤ localeAwareCompare (const QString &, const QString &): static functions: Compare the first and second strings. If the value is smaller than the first two strings, a negative integer value is returned. If the value is equal to 0, a positive integer is returned. If the value is greater than the value, a positive integer is returned .; ⑥ Compare (const QString &, const QString &, Qt: casesensiti.pdf): this function can be used to specify whether to perform case-sensitive comparison, the case-sensitivity comparison is fully character-based Unicode encoded values and is very fast. The returned value is similar to the localeAwareCompare () function.
1.3 String Conversion (1) QString: toInt () function converts a string to an integer value. Similar functions include toDouble (), toFloat (), toLong (), toLongLong (). The following is an example of its usage: QString str = "125"; bool OK; int hex = str. toInt (& OK, 16); // OK = true, hex = 293 int dec = str. toInt (& OK, 10); // OK = true, dec = 125 (2) The Conversion Function of the character sequence set provided by QString will return a QByteArray of the const char * type, that is, the QByteArray object constructed by the const char * const function. The QByteArray class has a byte array. It can store both raw bytes and traditional 8-bit strings ending with "\ 0. In Qt, QByteArray is more convenient than const char *, and QByteArray supports implicit sharing. There are several types of conversion functions. ① ToAscii (): returns an ASCII 8-Bit String .; ② ToLatin1 (): returns a Latin-1 (ISO8859-1) encoded 8-bit string; ③ toUtf8 (): returns a UTF-8 encoded 8-Bit String (UTF-8 is ASCII code super, it supports the entire Unicode Character Set); ④ toLocal8Bit (): returns an 8-Bit String encoded by the local system (locale. The following example illustrates the usage of QString str = "Welcome to you! "; QByteArray ba = str. toAscii (); qDebug () <ba; ba. append (" Hello, World! "); QDebug () <ba. data (); a NULL string is a QString object created using the default constructor of QString or using "(const char *) 0" as the constructor of the parameter; an empty string is a string with a size of 0. A null string must be an empty string, while a NULL string may not be a NULL string. For example, QString (). isNull (); // The result is true QString (). isEmpty (); // The result is true QString (""). isNull (); // The result is false QString (""). isEmpty (); // The result is true.
2. Container Class 2.1 QList class, qinilist class, And QVector class 2.1.1 QList class QList <T> are currently the most common container class, which stores a column of values of a given data type T. QList not only provides the QList: append () and Qlist: prepend () functions that can be appended to the list, but also provides the function QList :: insert (). QList <T> maintains a pointer array. the pointer stored in this array points to the content of the list item stored in QList <T>. For different data types, QList <T> adopts different storage policies. The storage policies are as follows. (1) If T is a pointer type or pointer size basic type (that is, the number of bytes occupied by this basic type is the same as the number of bytes occupied by the pointer type ), QList <T> stores the value directly in its array. (2) If QList <T> stores the object pointer, the Pointer Points to the actually stored object. The following is an example: # include <QDebug> int main (int argc, char * argv []) {QList <QString> list; {QString str ("This is a test string"); list <str ;}qdebug () <list [0] <"How are you! "; Return 0 ;}
2.1.2 qinilist class qinilist <T> is a chained list that stores data in discontinuous memory blocks. Qinilist <T> cannot use subscript. Only the iterator can be used to access its data items.
2.1.3 QVector <T> stores a group of values of the given data type T in the adjacent memory. QVector <T> you can use subscript to access data items or iterator to access data items.
2.1.4 the Java style iterator traverses the Java style iterator of the container. It is a new function added by Qt 4. For each container class, Qt provides two types of Java-style iterator data types: read-only access and read/write access. The following table lists their types.
2.1.5 The STL style iterator traverses the container. For each container class, Qt provides two types of STL style iterator data types: read-only access and read/write access. The two types of STL style iterators are listed in the table below.
2.2 QMap and QHash have similar functions. The difference is that: ① QHash has a faster search speed than QMap; ② QHash stores data items in any order, while QMap stores data in the Key-Key order. ③ the Key-type Key of QHash must provide operator = () and a global qHash (Key) function, while the Key type Key of QMap must provide the operator <() function. The time complexity comparison between the two is shown in the table below. 2.2.1 QMap class QMap <Key, T> provides a ing from a Key of type to a value of type T.
2.2.2 QHash class QHash <Key, T> has almost identical APIs with QMap. QHash maintains a Hash Table. The Hash Table size is consistent with the number of QHash data items.
2.2.3 Java style iterator traverses the container. For each container class, Qt provides two types of Java style iterator data types: read-only access and read/write access. The classification is shown in the table below. The following example describes how to insert, traverse, and modify QMap. # Include <QDebug> int main (int argc, char * argv []) {QMap <QString, QString> map; map. insert ("beijing", "111"); map. insert ("shanghai", "021"); map. insert ("nanjing", "025"); QMapIterator <QString, QString> I (map); for (; I. hasNext ();) {qDebug () <"" <I. key () <"" <I. next (). value ();} QMutableMapIterator <QString, QString> mi (map); if (mi. findNext ("111") {mi. setValue ("010");} QMapIterator <QString, QString> modi (map); qDebug () <"; for (; modi. hasNext ();) {qDebug () <"" <modi. key () <"" <modi. next (). value () ;}return 0 ;}
2.2.4 STL style iterator traverses the container. For each container class, Qt provides two types of STL style iterator data types: read-only access and read/write access. The classification is shown in the table below. The functions of the program below are basically the same as those of the Java style iterator. The difference is that the search key is used to modify the value. # Include <QDebug> int main (int argc, char * argv []) {QMap <QString, QString> map; map. insert ("beijing", "111"); map. insert ("shanghai", "021"); map. insert ("jinan", "0531"); QMap <QString, QString >:: const_iterator I; for (I = map. constBegin (); I! = Map. constEnd (); ++ I) {qDebug () <"" <I. key () <"" <I. value () ;}qmap <QString, QString >:: iterator mi; mi = map. find ("beijing"); if (mi! = Map. end () {mi. value () = "010" ;}qmap <QString, QString >:: const_iterator modi; qDebug () <"; for (modi = map. constBegin (); modi! = Map. constEnd (); ++ modi) {qDebug () <"" <modi. key () <"" <modi. value () ;}return 0 ;}
3 QVariant is similar to the union data type of C ++. It not only saves many values of the Qt type, including QColor, QBrush, QFont, QPen, QRect, QString, and QSize. It can also store the values of the Qt container type. Many functions of Qt are based on QVariant, such as object attributes and database functions of Qt.
4. The <QtAlgorithms> and <QtGlobal> modules of the 4.1 Qt5 common algorithm Qt provide some algorithms and functions. The following describes the usage of several common algorithms. # Include <QDebug> int main (int argc, char * argv []) {double a =-19.3, B = 9.7; double c = qAbs (); // c = 19.3 double max = qMax (B, c); // max = c = 19.3
Int bn = qRound (B); // bn = 10 int cn = qRound (c); // cn = 19
QDebug () <"a =" <a; qDebug () <"B =" <B; qDebug () <"c = qAbs () = "<c; qDebug () <" qMax (B, c) = "<max; qDebug () <" bn = qRound (B) = "<bn; qDebug () <" cn = qRound (c) = "<cn;
QSwap (bn, cn); qDebug () <"qSwap (bn, cn):" <"bn =" <bn <"cn =" <cn; return 0 ;}
4.2 A basic regular expression is composed of expressions (expressions), quantifiers, and assertions. (1) The simplest expression is a character. The expression to represent the character set can be used, for example, "[AEIOU]" to indicate matching all uppercase Vowels; "[^ AEIOU]" to indicate matching all non-vowels, I .e., consonants; continuous character sets can use expressions such as [a-z] to match all lower-case English letters. (2) quantifiers indicate the number of times the expression appears, for example, "x [1, 2]" indicates that "x" can have at least one and at most two. In computer languages, identifiers generally start with letters or underlines, followed by letters, numbers, and underlines. The identifier that meets the condition is: "[A-Za-z _] + [A-Za-z_0-9] *". The following table lists the regular expression quantifiers. (3) "^", "$", and "\ B" are both regular expression assertions. The regular expression assertions are shown in the following table.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.