[Kde-finance-apps] Re: AlkValue <-> QString round trip

Thomas Baumgart thb at net-bembel.de
Mon Mar 28 08:44:31 CEST 2011


Hi,

on Monday 28 March 2011 04:20:19 Alvaro Soliverez wrote:

> Hello Thomas,
> I'm working on a couple of Alkimia of classes used to send quotes
> value over DBus.
> For that, the classes have to be marshalled and demarshalled on arrival.
> 
> Looking at AlkValue, there's not a clear way to do the round-trip.
> Meaning, I have to convert AlkValue to QString (in that case,
> toString() should suffice), and the I'd need an equivalent
> fromString() method.
> 
> I see there's a constructor, but from the docs, that takes a regular
> currency string. I'd need one that takes the output of toString and
> returns a proper AlkValue.

Hmm, the docs clearly state that it takes 'our own toString() format' so that 
should not be a problem at all. The decimal symbol required does not matter in 
this case as none is contained in the toString() output.

> Did I miss it and it's hidden there somewhere?

  AlkValue a(100,1);
  QString s;
  s = a.toString();
  AlkValue b(s, '.');

should do the trick. You could also use the assignment operator as in

  AlkValue a;
  QString s("1/100");

  a = s;

which does not require the decimal symbol (as it defaults to the dot) but 
might be less efficient.


> I know I could parse the string and then call one of the constructors,
> but I'd rather avoid it if it's possible to have it in AlkValue
> itself, where it can be properly validated.

Please take a look at the following testcases:

AlkValueTest::equality()
void AlkValueTest::stringCtor() 2nd and 3rd case

> PS: I expect to have these classes ready for review this week, and
> I'll send them to you.

Sounds good.

-- 

Regards

Thomas Baumgart

GPG-FP: E55E D592 F45F 116B 8429   4F99 9C59 DB40 B75D D3BA
-------------------------------------------------------------
The shortest words, namely yes and no,
require the most thoughts. -- Pythagoras of Samos
-------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 225 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/kde-finance-apps/attachments/20110328/b76197bb/attachment.sig 


More information about the Kde-finance-apps mailing list