[Development] Converting types in Qt

Jędrzej Nowacki jedrzej.nowacki at digia.com
Wed Jul 16 11:28:53 CEST 2014


On Wednesday 16 of July 2014 06:37:25 Ziller Eike wrote:
>  [...]
> > When one use QVariant, it is because we want to enjoy dynamic typing and
> > nice  conversions.
> 
> 
> I don’t think we have a single place in Qt Creator where we want automatic
> conversions when using QVariant. A search for QVariant(Map) returns 5400
> hits. In the map case, we usually expect the one retrieving the value for
> a key to know the exact type of what was thrown in (that’s usually the same
> class, or related classes), and then we use item models and QSettings which
> we use in the same way. 
> Even if automatic conversion might be interesting (when, actually?), then
> the point is:
 
> There is no API in QVariant to support the common use case of getting the
> value *without* automatic conversion.

Nobody asked for it, It should be easy to implement something equal to this;

 Q_ASSUME(variant.userType() == qMetaType<TargetType>()); 
 TargetType data = variant.value<TargetType>();

I believe such new api make sense, we can add it.

> 
> >>> 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 ?
> 
> Br, Eike

What is wrong with string -> int or bytearray -> int?

> -- 
> Eike Ziller, Senior Software Engineer - Digia, Qt
> Digia Germany GmbH, Rudower Chaussee 13, D-12489 Berlin
> Geschäftsführer: Mika Pälsi, Juha Varelius, Anja Wasenius
> Sitz der Gesellschaft: Berlin. Registergericht: Amtsgericht Charlottenburg,
> HRB 144331 B 
 
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development





More information about the Development mailing list