[Development] Converting types in Qt

Olivier Goffart olivier at woboq.com
Wed Jul 16 12:51:36 CEST 2014


On Wednesday 16 July 2014 10:06:52 Poenitz Andre wrote:
> Jędrzej Nowacki wrote:
> > Eike wrote:
> > > [...]
> > > 
> > >>> We use common sense on a case by case basic.
> > > 
> > > Either there is no “common sense” common to me, or this rule has failed
> > > in
> > > the past already ;)
> > > bool -> string ?
> > > bytearray -> int/long/double ?
> > > keysequence -> int ?
> > > string -> bool ?
> > > string -> bytearray ?
> > > string -> int ?
> > 
> > What is wrong with string -> int or bytearray -> int?
> 
> At the very least, _implicit_ conversions should not lose data,
> i.e. a  A a1;  B b = a1; A a2 = b; round trip ideally should yield
> a1 == a2.
> 
> If I am ready to give up information, I'd like to need to say so
> in the code explicitly. (And yes, part of the deed is done in the
> core language, but even there compilers start to nag about it.)

André, QVariant conversions are not implicit, they are explicit.
You have to use qvariant_cast<T>, QVariant::value<T>, or QVariant::to*.
That's explicit.

Conversions _to_ QVariant are sometimes implicit, but they are loss-less as it 
just wrap the type into the QVariant.

-- 
Olivier 

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org



More information about the Development mailing list