Re: [Interest] unexpected result from QString::compare

2020-05-11 Thread Giuseppe D'Angelo via Interest

Il 11/05/20 10:23, Hamish Moffatt ha scritto:

Q_GLOBAL_STATIC(QThreadStorage, defaultCollator)

Why does it need an instance per thread?


Because QCollator is reentrant, not thread-safe.

HTH,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts



smime.p7s
Description: Firma crittografica S/MIME
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] unexpected result from QString::compare

2020-05-11 Thread Hamish Moffatt

On 9/5/20 12:35 am, Thiago Macieira wrote:


On Friday, 8 May 2020 05:05:43 PDT Hamish Moffatt wrote:


localeAwareCompare() is working as expected.


Unfortunately, it doesn't allow the case sensitivity to be specified 
(unlike QCollator::compare() and QString::compare()), which makes it 
less useful than it could be.



Consider QCollator too.



Thanks, that solves my next problem of how to compare in locales other 
than the default.


I notice that QString::localeAwareCompare() internally uses a QCollator, 
which it defines as;


Q_GLOBAL_STATIC(QThreadStorage, defaultCollator)

Why does it need an instance per thread?



Hamish
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] unexpected result from QString::compare

2020-05-08 Thread Thiago Macieira
On Friday, 8 May 2020 05:05:43 PDT Hamish Moffatt wrote:
> On 8/5/20 6:54 pm, Florian Bruhin wrote:
> > On Fri, May 08, 2020 at 08:51:19AM +, Hamish Moffatt wrote:
> >> On 8/5/20 5:13 pm, Fabrice Mousset | GEOCEPT GmbH wrote:
> >>> Perhaps you should use QString::localeAwareCompare() ?
> >> 
> >> Thanks, I didn't know about that. Maybe the QString::compare()
> >> documentation could mention it...
> >> 
> >  From https://doc.qt.io/qt-5/qstring.html#compare :
> >Case sensitive comparison is based exclusively on the numeric Unicode
> >values of the characters and is very fast, but is not what a human
> >would expect. Consider sorting user-visible strings with
> >localeAwareCompare().
> 
> Oh thanks, I'm at 0/2 today it seems. I looked at the compare() overload
> I'm using and missed this reference further up.
> 
> localeAwareCompare() is working as expected.

Consider QCollator too.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products



___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] unexpected result from QString::compare

2020-05-08 Thread Hamish Moffatt

On 8/5/20 6:54 pm, Florian Bruhin wrote:


On Fri, May 08, 2020 at 08:51:19AM +, Hamish Moffatt wrote:

On 8/5/20 5:13 pm, Fabrice Mousset | GEOCEPT GmbH wrote:

Perhaps you should use QString::localeAwareCompare() ?


Thanks, I didn't know about that. Maybe the QString::compare() documentation
could mention it...

 From https://doc.qt.io/qt-5/qstring.html#compare :

   Case sensitive comparison is based exclusively on the numeric Unicode values
   of the characters and is very fast, but is not what a human would expect.
   Consider sorting user-visible strings with localeAwareCompare().

Oh thanks, I'm at 0/2 today it seems. I looked at the compare() overload 
I'm using and missed this reference further up.


localeAwareCompare() is working as expected.

Hamish
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] unexpected result from QString::compare

2020-05-08 Thread Florian Bruhin
On Fri, May 08, 2020 at 08:51:19AM +, Hamish Moffatt wrote:
> On 8/5/20 5:13 pm, Fabrice Mousset | GEOCEPT GmbH wrote:
> > Perhaps you should use QString::localeAwareCompare() ?
> 
> 
> Thanks, I didn't know about that. Maybe the QString::compare() documentation
> could mention it...

From https://doc.qt.io/qt-5/qstring.html#compare :

  Case sensitive comparison is based exclusively on the numeric Unicode values
  of the characters and is very fast, but is not what a human would expect.
  Consider sorting user-visible strings with localeAwareCompare().

Florian

-- 
m...@the-compiler.org (Mail/XMPP) | https://www.qutebrowser.org 
   https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
 I love long mails! | https://email.is-not-s.ms/


signature.asc
Description: PGP signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] unexpected result from QString::compare

2020-05-08 Thread Hamish Moffatt

On 8/5/20 5:13 pm, Fabrice Mousset | GEOCEPT GmbH wrote:

Perhaps you should use QString::localeAwareCompare() ?



Thanks, I didn't know about that. Maybe the QString::compare() 
documentation could mention it...



Hamish

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] unexpected result from QString::compare

2020-05-08 Thread Fabrice Mousset | GEOCEPT GmbH
Perhaps you should use QString::localeAwareCompare() ?

BR

Fabrice

> -Ursprüngliche Nachricht-
> Von: Interest  Im Auftrag von Hamish
> Moffatt
> Gesendet: Freitag, 8. Mai 2020 08:27
> An: Qt Interest 
> Betreff: [Interest] unexpected result from QString::compare
> 
> I'm trying to sort a list of strings where umlauts are involved, and not 
> getting
> the answer I expect from QString::compare(). My sample code is:
> 
>          auto a = QStringLiteral("Äbc");
>          auto b = QStringLiteral("BCD");
>          auto c = a.compare(b);
>          qDebug() << a << b << c;
> 
> This produces the output:
> 
> "Äbc" "BCD" 130
> 
> which indicates that Äbc should be sorted after "BCD".
> 
> I get the same result when I load the strings through QTranslator so I don't
> believe there's any editor/encoding issue going on.
> 
> I seem to get the right result when I let QListWidget sort the items for me
> though.
> 
> 
> What am I missing?
> 
> 
> thanks,
> 
> Hamish
> 
> 
> ___
> Interest mailing list
> Interest@qt-project.org
> https://lists.qt-project.org/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] unexpected result from QString::compare

2020-05-08 Thread Hamish Moffatt
I'm trying to sort a list of strings where umlauts are involved, and not 
getting the answer I expect from QString::compare(). My sample code is:


        auto a = QStringLiteral("Äbc");
        auto b = QStringLiteral("BCD");
        auto c = a.compare(b);
        qDebug() << a << b << c;

This produces the output:

"Äbc" "BCD" 130

which indicates that Äbc should be sorted after "BCD".

I get the same result when I load the strings through QTranslator so I 
don't believe there's any editor/encoding issue going on.


I seem to get the right result when I let QListWidget sort the items for 
me though.



What am I missing?


thanks,

Hamish


___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest