QCollator: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Waldyrious (talk | contribs) (add example) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{ | == Available features by platform == | ||
{| class="wikitable" | |||
| | |||
! ICU | |||
! POSIX | |||
! Mac OS X | |||
! Windows | |||
|- | |||
|casePreference | |||
| Y | |||
| N | |||
| Y | |||
| Y | |||
|- | |||
|numericMode | |||
| Y | |||
| N | |||
| Y | |||
| N¹ | |||
|- | |||
|ignorePunctuation | |||
| Y | |||
| N | |||
| Y | |||
| Y | |||
|- | |||
|compare | |||
| Y | |||
| Y | |||
| Y | |||
| Y | |||
|- | |||
|sortKey | |||
| Y | |||
| Y | |||
| Y | |||
| Y | |||
|} | |||
¹ Only available since Win7 | ¹ Only available since Win7 | ||
== Example: Sorting a QStringList using QCollator == | |||
<code> | |||
#include <QStringList> | |||
#include <QCollator> | |||
#include <QDebug> | |||
int main( int argc, char *argv[] ) | |||
{ | |||
QStringList myStringList = (QStringList() << "abc123" << "ABc99" << "1234abcd"); | |||
QCollator sorter; | |||
sorter.setNumericMode( true ); // Default is false | |||
sorter.setCaseSensitivity( Qt::CaseInsensitive ); // Default is case sensitive | |||
std::sort( myStringList.begin(), myStringList.end(), [&]( const QString& a, const QString& b ) { | |||
return sorter.compare( a, b ) < 0; | |||
} ); | |||
qDebug() << myStringList; | |||
} | |||
</code> | |||
The code above should output the following: | |||
:<tt>("1234abcd", "ABc99", "abc123")</tt> |
Latest revision as of 15:57, 1 July 2016
Available features by platform
ICU | POSIX | Mac OS X | Windows | |
---|---|---|---|---|
casePreference | Y | N | Y | Y |
numericMode | Y | N | Y | N¹ |
ignorePunctuation | Y | N | Y | Y |
compare | Y | Y | Y | Y |
sortKey | Y | Y | Y | Y |
¹ Only available since Win7
Example: Sorting a QStringList using QCollator
#include <QStringList>
#include <QCollator>
#include <QDebug>
int main( int argc, char *argv[] )
{
QStringList myStringList = (QStringList() << "abc123" << "ABc99" << "1234abcd");
QCollator sorter;
sorter.setNumericMode( true ); // Default is false
sorter.setCaseSensitivity( Qt::CaseInsensitive ); // Default is case sensitive
std::sort( myStringList.begin(), myStringList.end(), [&]( const QString& a, const QString& b ) {
return sorter.compare( a, b ) < 0;
} );
qDebug() << myStringList;
}
The code above should output the following:
- ("1234abcd", "ABc99", "abc123")