[PyQt] QVariant and QList

cadevel cadevel at free.fr
Thu Apr 29 13:01:00 BST 2010


Phil Thompson a écrit :
> On Thu, 29 Apr 2010 13:17:05 +0200, cadevel <cadevel at free.fr> wrote:
>   
>> Phil Thompson a écrit :
>>     
>>> On Thu, 29 Apr 2010 09:49:06 +0200, cadevel <cadevel at free.fr> wrote:
>>>   
>>>       
>>>> Hello,
>>>>
>>>> How can i convert a QVariant containing a QList<QNetworkCookie> to a 
>>>> python list of QNetworkCookie.
>>>>     
>>>>         
>>> What's the context? What is creating the QVariant?
>>>
>>> Phil
>>>   
>>>       
>> QVariant <qvariant.html> QNetworkReply::header 
>> ( QNetworkRequest::KnownHeaders 
>> <qnetworkrequest.html#KnownHeaders-enum> /header/ ) const
>> with hdr = QNetworkRequest::CookieHeader
>>
>> ( corresponds to the HTTP Cookie header and contains aQList 
>> <qlist.html><QNetworkCookie <qnetworkcookie.html>> representing the 
>> cookies to be sent back to the server )
>>
>> Christophe
>>     
>
> I assume you have tried the obvious QVariant.toPyObject().
>
> Do you have a short test that I can run and will generate such a QVariant?
>
> Phil
>   

Yes i tried  toPyObject() but it generates an exception


# -*- coding: utf-8 -*-
from PyQt4 import  QtCore
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest, 
QNetworkCookieJar
import sys

app=QtCore.QCoreApplication(sys.argv)


def on_finish():
    variant = reply.header(QNetworkRequest.SetCookieHeader)
    print variant
   
    app.quit()

nwm = QNetworkAccessManager()
reply = nwm.get(QNetworkRequest(QtCore.QUrl('http://www.google.com')))
app.connect(reply,QtCore.SIGNAL('finished()'), on_finish)

app.exec_()



More information about the PyQt mailing list