<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qcollator.cpp --> <title>QCollator Class | Qt Core 5.12.6</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.12</td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QCollator</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtcore-index.html">Qt 5.12.6 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QCollator Class</h1> <!-- $$$QCollator-brief --> <p>The <a href="qcollator.html">QCollator</a> class compares strings according to a localized collation algorithm. <a href="#details">More...</a></p> <!-- @@@QCollator --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QCollator></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign"> Qt 5.2</td></tr></table></div><ul> <li><a href="qcollator-members.html">List of all members, including inherited members</a></li> </ul> <p><b>Note:</b> All functions in this class are reentrant.</p> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#QCollator">QCollator</a></b>(const QLocale &<i>locale</i> = QLocale())</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#QCollator-1">QCollator</a></b>(const QCollator &<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#QCollator-2">QCollator</a></b>(QCollator &&<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#dtor.QCollator">~QCollator</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> Qt::CaseSensitivity </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#caseSensitivity">caseSensitivity</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#compare">compare</a></b>(const QString &<i>s1</i>, const QString &<i>s2</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#compare-1">compare</a></b>(const QStringRef &<i>s1</i>, const QStringRef &<i>s2</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#compare-2">compare</a></b>(const QChar *<i>s1</i>, int <i>len1</i>, const QChar *<i>s2</i>, int <i>len2</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#ignorePunctuation">ignorePunctuation</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QLocale </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#locale">locale</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#numericMode">numericMode</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#setCaseSensitivity">setCaseSensitivity</a></b>(Qt::CaseSensitivity <i>sensitivity</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#setIgnorePunctuation">setIgnorePunctuation</a></b>(bool <i>on</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#setLocale">setLocale</a></b>(const QLocale &<i>locale</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#setNumericMode">setNumericMode</a></b>(bool <i>on</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QCollatorSortKey </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#sortKey">sortKey</a></b>(const QString &<i>string</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#swap">swap</a></b>(QCollator &<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QCollator &</td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#operator-eq">operator=</a></b>(const QCollator &<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QCollator &</td><td class="memItemRight bottomAlign"><b><a href="qcollator.html#operator-eq-1">operator=</a></b>(QCollator &&<i>other</i>)</td></tr> </table></div> <a name="details"></a> <!-- $$$QCollator-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qcollator.html">QCollator</a> class compares strings according to a localized collation algorithm.</p> <p><a href="qcollator.html">QCollator</a> is initialized with a <a href="qlocale.html">QLocale</a> and an optional collation strategy. It tries to initialize the collator with the specified values. The collator can then be used to compare and sort strings in a locale dependent fashion.</p> <p>A <a href="qcollator.html">QCollator</a> object can be used together with template based sorting algorithms such as std::sort to sort a list of QStrings.</p> <p>In addition to the locale and collation strategy, several optional flags can be set that influence the result of the collation.</p> </div> <!-- @@@QCollator --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QCollator[overload1]$$$QCollatorconstQLocale& --> <h3 class="fn" id="QCollator"><a name="QCollator"></a>QCollator::<span class="name">QCollator</span>(const <span class="type"><a href="qlocale.html">QLocale</a></span> &<i>locale</i> = QLocale())</h3> <p>Constructs a <a href="qcollator.html">QCollator</a> from <i>locale</i>. If <i>locale</i> is not specified the system's default locale is used.</p> <p><b>See also </b><a href="qcollator.html#setLocale">setLocale</a>().</p> <!-- @@@QCollator --> <!-- $$$QCollator$$$QCollatorconstQCollator& --> <h3 class="fn" id="QCollator-1"><a name="QCollator-1"></a>QCollator::<span class="name">QCollator</span>(const <span class="type"><a href="qcollator.html#QCollator">QCollator</a></span> &<i>other</i>)</h3> <p>Creates a copy of <i>other</i>.</p> <!-- @@@QCollator --> <!-- $$$QCollator$$$QCollatorQCollator&& --> <h3 class="fn" id="QCollator-2"><a name="QCollator-2"></a>QCollator::<span class="name">QCollator</span>(<span class="type"><a href="qcollator.html#QCollator">QCollator</a></span> &&<i>other</i>)</h3> <p>Move constructor. Moves from <i>other</i> into this collator.</p> <p>Note that a moved-from <a href="qcollator.html">QCollator</a> can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.</p> <!-- @@@QCollator --> <!-- $$$~QCollator[overload1]$$$~QCollator --> <h3 class="fn" id="dtor.QCollator"><a name="dtor.QCollator"></a>QCollator::<span class="name">~QCollator</span>()</h3> <p>Destroys the collator.</p> <!-- @@@~QCollator --> <!-- $$$caseSensitivity[overload1]$$$caseSensitivity --> <h3 class="fn" id="caseSensitivity"><a name="caseSensitivity"></a><span class="type"><a href="qt.html#CaseSensitivity-enum">Qt::CaseSensitivity</a></span> QCollator::<span class="name">caseSensitivity</span>() const</h3> <p>Returns case sensitivity of the collator.</p> <p><b>See also </b><a href="qcollator.html#setCaseSensitivity">setCaseSensitivity</a>().</p> <!-- @@@caseSensitivity --> <!-- $$$compare[overload1]$$$compareconstQString&constQString& --> <h3 class="fn" id="compare"><a name="compare"></a><span class="type">int</span> QCollator::<span class="name">compare</span>(const <span class="type"><a href="qstring.html">QString</a></span> &<i>s1</i>, const <span class="type"><a href="qstring.html">QString</a></span> &<i>s2</i>) const</h3> <p>Compares <i>s1</i> with <i>s2</i>. Returns an integer less than, equal to, or greater than zero depending on whether <i>s1</i> is smaller, equal or larger than <i>s2</i>.</p> <!-- @@@compare --> <!-- $$$compare$$$compareconstQStringRef&constQStringRef& --> <h3 class="fn" id="compare-1"><a name="compare-1"></a><span class="type">int</span> QCollator::<span class="name">compare</span>(const <span class="type"><a href="qstringref.html">QStringRef</a></span> &<i>s1</i>, const <span class="type"><a href="qstringref.html">QStringRef</a></span> &<i>s2</i>) const</h3> <p>This is an overloaded function.</p> <p>Compares <i>s1</i> with <i>s2</i>. Returns an integer less than, equal to, or greater than zero depending on whether <i>s1</i> is smaller, equal or larger than <i>s2</i>.</p> <!-- @@@compare --> <!-- $$$compare$$$compareconstQChar*intconstQChar*int --> <h3 class="fn" id="compare-2"><a name="compare-2"></a><span class="type">int</span> QCollator::<span class="name">compare</span>(const <span class="type"><a href="qchar.html">QChar</a></span> *<i>s1</i>, <span class="type">int</span> <i>len1</i>, const <span class="type"><a href="qchar.html">QChar</a></span> *<i>s2</i>, <span class="type">int</span> <i>len2</i>) const</h3> <p>This is an overloaded function.</p> <p>Compares <i>s1</i> with <i>s2</i>. <i>len1</i> and <i>len2</i> specify the length of the <a href="qchar.html">QChar</a> arrays pointer to by <i>s1</i> and <i>s2</i>.</p> <p>Returns an integer less than, equal to, or greater than zero depending on whether <i>s1</i> is smaller, equal or larger than <i>s2</i>.</p> <!-- @@@compare --> <!-- $$$ignorePunctuation[overload1]$$$ignorePunctuation --> <h3 class="fn" id="ignorePunctuation"><a name="ignorePunctuation"></a><span class="type">bool</span> QCollator::<span class="name">ignorePunctuation</span>() const</h3> <p>Returns <code>true</code> if punctuation characters and symbols are ignored when determining sort order.</p> <p><b>See also </b><a href="qcollator.html#setIgnorePunctuation">setIgnorePunctuation</a>().</p> <!-- @@@ignorePunctuation --> <!-- $$$locale[overload1]$$$locale --> <h3 class="fn" id="locale"><a name="locale"></a><span class="type"><a href="qlocale.html">QLocale</a></span> QCollator::<span class="name">locale</span>() const</h3> <p>Returns the locale of the collator.</p> <p><b>See also </b><a href="qcollator.html#setLocale">setLocale</a>().</p> <!-- @@@locale --> <!-- $$$numericMode[overload1]$$$numericMode --> <h3 class="fn" id="numericMode"><a name="numericMode"></a><span class="type">bool</span> QCollator::<span class="name">numericMode</span>() const</h3> <p>Returns <code>true</code> if numeric sorting is enabled, false otherwise.</p> <p><b>See also </b><a href="qcollator.html#setNumericMode">setNumericMode</a>().</p> <!-- @@@numericMode --> <!-- $$$setCaseSensitivity[overload1]$$$setCaseSensitivityQt::CaseSensitivity --> <h3 class="fn" id="setCaseSensitivity"><a name="setCaseSensitivity"></a><span class="type">void</span> QCollator::<span class="name">setCaseSensitivity</span>(<span class="type"><a href="qt.html#CaseSensitivity-enum">Qt::CaseSensitivity</a></span> <i>sensitivity</i>)</h3> <p>Sets the case <i>sensitivity</i> of the collator.</p> <p><b>See also </b><a href="qcollator.html#caseSensitivity">caseSensitivity</a>().</p> <!-- @@@setCaseSensitivity --> <!-- $$$setIgnorePunctuation[overload1]$$$setIgnorePunctuationbool --> <h3 class="fn" id="setIgnorePunctuation"><a name="setIgnorePunctuation"></a><span class="type">void</span> QCollator::<span class="name">setIgnorePunctuation</span>(<span class="type">bool</span> <i>on</i>)</h3> <p>If <i>on</i> is set to true, punctuation characters and symbols are ignored when determining sort order.</p> <p>The default is locale dependent.</p> <p><b>Note: </b>This method is not currently supported if Qt is configured to not use ICU on Linux.</p><p><b>See also </b><a href="qcollator.html#ignorePunctuation">ignorePunctuation</a>().</p> <!-- @@@setIgnorePunctuation --> <!-- $$$setLocale[overload1]$$$setLocaleconstQLocale& --> <h3 class="fn" id="setLocale"><a name="setLocale"></a><span class="type">void</span> QCollator::<span class="name">setLocale</span>(const <span class="type"><a href="qlocale.html">QLocale</a></span> &<i>locale</i>)</h3> <p>Sets the locale of the collator to <i>locale</i>.</p> <p><b>See also </b><a href="qcollator.html#locale">locale</a>().</p> <!-- @@@setLocale --> <!-- $$$setNumericMode[overload1]$$$setNumericModebool --> <h3 class="fn" id="setNumericMode"><a name="setNumericMode"></a><span class="type">void</span> QCollator::<span class="name">setNumericMode</span>(<span class="type">bool</span> <i>on</i>)</h3> <p>Enables numeric sorting mode when <i>on</i> is set to true.</p> <p>This will enable proper sorting of numeric digits, so that e.g. 100 sorts after 99.</p> <p>By default this mode is off.</p> <p><b>See also </b><a href="qcollator.html#numericMode">numericMode</a>().</p> <!-- @@@setNumericMode --> <!-- $$$sortKey[overload1]$$$sortKeyconstQString& --> <h3 class="fn" id="sortKey"><a name="sortKey"></a><span class="type"><a href="qcollatorsortkey.html">QCollatorSortKey</a></span> QCollator::<span class="name">sortKey</span>(const <span class="type"><a href="qstring.html">QString</a></span> &<i>string</i>) const</h3> <p>Returns a sortKey for <i>string</i>.</p> <p>Creating the sort key is usually somewhat slower, than using the <a href="qcollator.html#compare">compare</a>() methods directly. But if the string is compared repeatedly (e.g. when sorting a whole list of strings), it's usually faster to create the sort keys for each string and then sort using the keys.</p> <p><b>Note: </b>Not supported with the C (a.k.a. POSIX) locale on Darwin.</p><!-- @@@sortKey --> <!-- $$$swap[overload1]$$$swapQCollator& --> <h3 class="fn" id="swap"><a name="swap"></a><span class="type">void</span> QCollator::<span class="name">swap</span>(<span class="type"><a href="qcollator.html#QCollator">QCollator</a></span> &<i>other</i>)</h3> <p>Swaps this collator with <i>other</i>. This function is very fast and never fails.</p> <!-- @@@swap --> <!-- $$$operator=[overload1]$$$operator=constQCollator& --> <h3 class="fn" id="operator-eq"><a name="operator-eq"></a><span class="type"><a href="qcollator.html#QCollator">QCollator</a></span> &QCollator::<span class="name">operator=</span>(const <span class="type"><a href="qcollator.html#QCollator">QCollator</a></span> &<i>other</i>)</h3> <p>Assigns <i>other</i> to this collator.</p> <!-- @@@operator= --> <!-- $$$operator=$$$operator=QCollator&& --> <h3 class="fn" id="operator-eq-1"><a name="operator-eq-1"></a><span class="type"><a href="qcollator.html#QCollator">QCollator</a></span> &QCollator::<span class="name">operator=</span>(<span class="type"><a href="qcollator.html#QCollator">QCollator</a></span> &&<i>other</i>)</h3> <p>Move-assigns from <i>other</i> to this collator.</p> <p>Note that a moved-from <a href="qcollator.html">QCollator</a> can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.</p> <!-- @@@operator= --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>