有关qt的大小写敏感操作

遇到一种就在此文章上继续添加:

1. QComboBox

#include 
#include 

QCompleter sensitive;
sensitive.setCaseSensitivity(Qt::CaseSensitive);
//Qt::CaseSensitive 大小写敏感  
//Qt::CaseInsensitive 大小写不敏感(QComboBox默认)
QComboBox::setCompleter(&sensitive);

2. QString
QString有很多函数都有参数来选择大小写敏感,如:

int compare(const QString &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

bool contains(const QString &str, Qt::CaseSensitivity cs = ...) const

int count(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

int indexOf(const QString &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

int lastIndexOf(const QString &str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

QString &remove(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive)

QString &replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive)

QStringList split(const QString &sep, QString::SplitBehavior behavior = KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

QVector<QStringRef> splitRef(const QString &sep, QString::SplitBehavior behavior = KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const

等等。。。
所以需要手动指定大小写敏感时只需要如下操作即可

QString a("AaaaA");
QString b("aaAA");

a.contains(b, Qt::CaseInsensitive);	//大小写不敏感的contains  返回值为true
a.contains(b, Qt::CaseSensitive);	//大小写敏感的contains	返回值为false

你可能感兴趣的:(Qt,qt)