Thank you for the help.

int a=(Integer)settings.value("a",6); // this is how you return an
integer...
boolean b=(Boolean)settings.value("b",true); // and this is how you return
a boolean...

Appears to work just fine.

Regards

Ralf


On Mon, Jun 11, 2012 at 1:33 PM, Darryl Miles <
darryl-mailingli...@netbauds.net> wrote:

> Samu Voutilainen wrote:
>
>> maanantai 11 kesäkuu 2012 09:25:36 Ralf Van Bogaert kirjoitti:
>>
>>  When retrieving values with QSettings, the value is returned as a Java
>>> object by default. I can typecast it to a string if needed, but in
>>> many cases the values returned are integers or booleans and I'm not quite
>>> sure how to handle that efficiently, since I can't cast them to the
>>> desired
>>> type.
>>>
>>> Normally Qt returns the value as a QVariant which has methods such as
>>> toBool() and toInt(), however I can't use this in QtJambi.
>>>
>>> How is this done?
>>>
>>
> Think of it like Java has RTTI turned on by default for all objects.
>
> Many Qt/QVariant/C++ types have strightforward native Java types.
>
> Things that are outside this rule get wrapped.
>
>
>
>  With integers you can do (Integer) typecasting. (from documentation)
>> http://doc.qt.nokia.com/**qtjambi-4.5.2_01/com/**
>> trolltech/qt/core/QSettings.**html<http://doc.qt.nokia.com/qtjambi-4.5.2_01/com/trolltech/qt/core/QSettings.html>
>>
>> There is similar class for boolean, so cast (Boolean) should work out of
>> the
>> box too.
>>
>
> Not tried the API myself from QtJambi to type cast in Java would be
> something like:
>
>
> Object variableOfUnknownType = someQSettingObject.value("key"**);
>
> if(variableOfUnknownType instanceof Integer) {
>   Integer i = (Integer) variableOfUnknownType;
>   // do work with "i" here
> } else if(variableOfUnknownType instanceof Boolean) {
>   Boolean b = (Boolean) variableOfUnknownType;
>   // do work with "b" here
> } else if(variableOfUnknownType instanceof String) {
>   String s = (String) variableOfUnknownType;
>   // do work with "s" here
> } else if(variableOfUnknownType == null) {
>   // it was null (Java type information can not help you here)
> } else {
>   // Do something when we didn't handle the type
>   System.out.println("object of type " + 
> variableOfUnknownType.**getClass().getName()
> + " not handled for value: " + variableOfUnknownType.**toString());
> }
>
>
>
> HTH
>
> Darryl
>
_______________________________________________
Qt-jambi-interest mailing list
Qt-jambi-interest@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest

Reply via email to