[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Do not avto convert python date to QVariant
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2009-05-26 11:56:30
Message-ID: fc5e83c0758a7f2d624963b7d04e8272 () localhost
[Download RAW message or body]

On Tue, 26 May 2009 16:49:10 +0700, Alexandr N Zamaraev <tonal@promsoft.ru>
wrote:
> [code]
> from PyQt4 import QtCore
> import datetime
> 
> def show(d, QtType):
>    print 'pytype:', d
>    v = QtCore.QVariant(d)
>    print 'from variant:', str(QtCore.QVariant(d).toString())
>    print 'from qttype:', str(QtCore.QVariant(QtType(d)).toString())
> 
> show(datetime.date.today(), QtCore.QDate)
> print
> show(datetime.datetime.today(), QtCore.QDateTime)
> print
> show(datetime.datetime.today().time(), QtCore.QTime)
> [/code]
> In PyQt 4.4.4 all converts.

This is a deliberate change. It is documented - but I'll expand the
documentation to mention the datetime types explicitly. Use toPyObject() to
get the Python datetime instances back.

If you want the old behaviour then convert the Python types to their Qt
equivalents before converting to QVariant - and that will work Ok with
earlier versions as well.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic