[Qt-interest] QVariant is great, make it better

Mildred Ki'Lya ml.mildred593 at gmail.com
Thu Jul 9 21:05:52 CEST 2009


On 07/08/2009 01:06 PM, Thiago Macieira wrote:
> Mildred Ki'Lya wrote:
>   
>> QVariant IPv4::qvariantToType(QVariant::Type t); // convert this to a
>> QVariant of type t
>> QVariant IPv4::qvariantFromValue(QVariant origin); // convert origin to
>> an IPv4 QVariant
>>
>> Well, that could be done outside the QVariant class, but it would be
>> really great I think if there was some functionnality like this.
>>     
> Hi Mildred
>
> This is something I've tried to do, but I haven't been able to get the 
> template-magic to work.

Hi,

Well, I needed it, so I did it. And no need for templates. Here is my code.

It's not perfect, especially since I'm using QVariant::data() which
returns me a pointer on the value held in the QVariant, and I don't
think this is a public interface. And since QVariant::data() returns a
void*, there is no way to cast it back to QObject* so we could use
qobject_cast.

My solution: have a static variable which is a set of every value
created, and test the pointer returned by QVariant::data() with the
content of the set to determine if the value can be casted back to QObject.


:)

Mildred


-- 
Mildred Ki'Lya
╭───────── mildred593@online.fr ──────────
│ Jabber, GoogleTalk: <mildred at jabber.fr>
│ Website: <http://ki.lya.online.fr>           GPG ID: 9A7D 2E2B
│ Fingerprint: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ivalue.h
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/b96b38e8/attachment.h 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ivalue.cpp
Type: text/x-c++src
Size: 448 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/b96b38e8/attachment.bin 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ipaddress.h
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/b96b38e8/attachment-0001.h 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipaddress.cpp
Type: text/x-c++src
Size: 1020 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/b96b38e8/attachment-0001.bin 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_ivalue.h
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/b96b38e8/attachment-0002.h 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_ivalue.cpp
Type: text/x-c++src
Size: 1952 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/b96b38e8/attachment-0002.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/b96b38e8/attachment-0003.bin 


More information about the Qt-interest-old mailing list