[Development] Converting types in Qt

Poenitz Andre Andre.Poenitz at digia.com
Wed Jul 16 13:45:13 CEST 2014


Olivier Goffart wrote:
> Jędrzej Nowacki wrote:
> [...]
> > > 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.

I am aware of that. I tried to answer the question of "What is wrong 
with string -> int or bytearray -> int". 

We admittedly left the original context here (and in other parts of the 
discussion), but the question was posed in context that I read an 
example of an conversion that one would always consider convenient
to have, and I started with "At the very least, _implicit.." supposedly 
setting the context of the answer.

Anyway. To summarize my position in the original context: QVariant 
is as it is. It is convenient at times, and it is already too convenient 
at times. "Easy type conversion" is a different use case than "Type 
agnostic storage". QVariant does a bit of both, only the second one
has ever been useful _to me_, I have been bitten by the first. As 
there are typically also more direct ways to convert types than to 
pass through QVariant, I consider the possibility to do type conversion
through QVariant a mis-feature, and adding even more conversion 
abilities would be a step into the wrong direction _for me_. This is 
a personal opinion.

Andre'



More information about the Development mailing list