[Gambas-user] Combobox1.sort=true sorts different then Astring.sort

Benoit Minisini gambas at ...1...
Wed Jan 9 16:44:16 CET 2008


On mercredi 9 janvier 2008, gaupe wrote:
> ron thanks for the complete explanation of how qt does this
>
>
> i get the system
> and the example was not in one sequential order
> the second one was standalone and
> combobox1.sort was default false so id did what you suggest there later.
>
> My meaning however stays that i now have to, in one language constantly
> think.
>
>
> ehhh... sort was it the interpreter was it qt was it sometehing else...
>
> it gets confusing
>
> same with the utf-8 thingy in gambas
>
> as soon as you go out of the standard simple ascii you suddenly are
> confronted with the fact that
> asc and chr do not get utf-8
> and have to use other means like string.length and so on to solve it.
>
> one time you can use len($this)
> the other time you have to use string.length(this) (or was it another
> synax.. youll get wat im aiming at i guess)
>
> would be nice in my opinion that all would use One standard.
>
>
> But hey thats life and i can live with it ;-)
>
> Ron Onstenk wrote:
> > On Wednesday 09 January 2008 12:09, gaupe wrote:
> >> Why does the combobox.sort=true
> >> sort different then a sort in a string array?
> >> would be very confusing (if i didnt make a mistake :-/)
> >>
> >> if i have
> >>
> >> dim Astring as new string[]
> >>
> >> ["-this-","Ape"]
> >>
> >> then
> >>
> >> combobox1.list=Astring
> >> combobox.sort=TRUE
> >>
> >> first item in list will be "Ape"
> >>
> >> gives a different result from
> >>
> >> astring.sort
> >> combobox1.list=astring
> >> combobox.sort=FALSE
> >>
> >> First item in list will be "-this-"
> >
> > If you sort the string array it sorts the value of each entry.
> > The key of the items are keep to the entry and are mangled.
> > Here now as [1], [0]
> >
> > I asume next hapens:
> >
> > 1)
> > When you put the array into the combobox the entry order (keys)
> > are in sequential order restored by qt.
> > Setting 'combobox.sort=FALSE' should not change the values.
> > Setting 'combobox.sort=true' should  order the values.
> >
> >
> > 2) The values are in the same order as the array after 'astring.sort'
> > and the keys are mangled.
> > Setting 'combobox.sort=FALSE' tels QT to restore the sequential order
> > by key values.
> >
> >
> >
> > Alternatives:
> >
> > When you copy the sorted values from astring entry by entry to a new
> > string array (bstring) wich reorders the key in the same order as values.
> > After the copy do combobox1.list=bstring.
> >
> > You can also add the items with foreach to the combobox after the
> > astring.sort.
> > In this way 'combobox.sort=FALSE' should not change the order.
> >
> >
> >
> > Ron
> >
> >> Because QT sorts differently than the interpreter.
> >
> > As Benoit says
> >
> > The '-' and '_' (minus and underscore) behaviour with sorting in qt
> > is also noticed in konqueror with filenames.
> > starting with '-' to get it as first in directory listing does not work.
> > It takes the first alfabet character instead of '-' or '_'.
> > Anyway at my box with kubuntu.
> >

To know how to sort strings in Gambas, I suggest reading the documentation 
about the String class, understanding what UTF-8 is, and looking at the 
documentation of the String[].Sort() method that can sort UTF-8 strings 
according to the locale, but not necessarily the same way as QT.

Regards,

-- 
Benoit Minisini




More information about the User mailing list