[Development] Converting types in Qt

Ziller Eike Eike.Ziller at digia.com
Thu Jul 17 10:51:03 CEST 2014

On Jul 16, 2014, at 1:45 PM, Poenitz Andre <Andre.Poenitz at digia.com> wrote:

> 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”. 

QVariant::operator== is not symmetric :( :( :(

     QDateTime dateTime = QDateTime::currentDateTime();
    QTime time = dateTime.time();

    qDebug() << (QVariant(dateTime) == QVariant(time));
    qDebug() << (QVariant(time) == QVariant(dateTime));


> 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'

Eike Ziller, Senior Software Engineer - Digia, Qt
Digia Germany GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B

More information about the Development mailing list