1 開發環境
在介紹內容之前,先說明一下開發環境,如下圖:
Qt版本:Qt5.3.2;
Qt開發工具:Qt Creater 3.2.1;
Qt構建工具:Desktop Qt 5.3 MinGW 32bit;
Qt開發平臺:Windows 7 64bit。
2 QString
今天介紹QString的比較部分的功能,之前的內容可以參考以下鏈接。
0022:Qt常用類 - QString(01,QString的編碼方式和初始化)
0023:Qt常用類 - QString(02,增加)
0024:Qt常用類 - QString(03,刪除)
0025:Qt常用類 - QString(04,修改)
0026:Qt常用類 - QString(05,查詢)
0027:Qt常用類 - QString(06,遍歷)
0028:Qt常用類 - QString(07,子字符串)
0029:Qt常用類 - QString(08,格式化)
下面是比較部分的示例代碼。
/*
* compare(const QString &other, Qt::CaseSensitivity cs)
* localeAwareCompare(const QString &other)
* operator==(const char *other)
* operator<(const char *other)
* operator<=(const char *other)
* operator>(const char *other)
* operator>=(const char *other)
*/
//compare(const QString &other, Qt::CaseSensitivity cs)
QString strComp = "12345abcde一二三四五";
qDebug("compare: result = %d.", strComp.compare("12345abcde一二三四五"));
//localeAwareCompare(const QString &other)
qDebug("localeAwareCompare: result = %d.", strComp.localeAwareCompare("23456"));
//operator==(const char *other)
qDebug("==: result = %d.", strComp == "23456abcde一二三四五");
//operator<(const char *other)
qDebug("<: result = %d.", strComp < "23456abcde一二三四五");
//operator<=(const char *other)
qDebug("<=: result = %d.", strComp <= "12345abcde一二三四五");
//operator>(const char *other)
qDebug(">: result = %d.", strComp > "23456abcde一二三四五");
//operator>=(const char *other)
qDebug(">=: result = %d.", strComp >= "23456abcde一二三四五");
在學習過程中,可以將上述代碼放到一個按鈕的響應函數中,以調試方式運行,就可以在Qt Creater中的應用程序輸出窗口看到輸出結果了。