[Qt5-feedback] QVariant::toString() and custom types

Thiago Macieira thiago at kde.org
Mon Jul 18 13:31:46 CEST 2011


On Sunday, 17 de July de 2011 23:50:26 Konstantin Ritt wrote:
> why not something simple like:
> 
> template <typename T> inline bool QVariant::canConvert() const
> { return m_type >= QVariant::User ? qVariantCanConvert<T>(*this) : /*
> internal implementation */; }
>  template <typename T> inline T QVariant::convert() const
> { return m_type >= QVariant::User ? qVariantValue<T>(*this) : /* internal
> implementation */; }
> ?
> it makes it possible to convert to an arbitrary type rather than just to
> QString...

Go ahead and try this.

Be sure to test with several compilers, as template programming usually finds 
different behaviours in compilers.

Or you can declare a C++0x-only feature, like some of the QString work we've 
done.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt.nokia.com/pipermail/qt5-feedback/attachments/20110718/bd1c28ef/attachment.bin 


More information about the Qt5-feedback mailing list