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

ron ronstk at ...239...
Wed Jan 9 13:42:02 CET 2008


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.







More information about the User mailing list