2012-06-20 2 views
0

저는 Python 및 PyQt4로 프로젝트를 끝내려고하고 있으며, 내가 작성한 함수를 통해 QLineEdit 변수를 전달하는 데 문제가 있습니다. 문자열은 URL로 작업을해야 내가 URL을 읽고 그 내용을 얻기 위해 시도 내 첫 번째 인수를 통해 통과 할 때, 그것은 나에게이 오류가 발생합니다 :QLineEdit 및 사용자 정의 함수 비 호환성

Traceback (most recent call last): 
    File "programa2.py", line 158, in on_link_clicked 
    download_mango(self.a, self.path2) 

    File "c:\Users\Poblet\ManGet\mango.py", line 19, in download_mango 
    urlContent = urllib2.urlopen(url).read() # We read the URL 

    File "c:\Python27\lib\urllib2.py", line 126, in urlopen 
    return _opener.open(url, data, timeout) 

    File "c:\Python27\lib\urllib2.py", line 386, in open 
    protocol = req.get_type() 

AttributeError: 'QString' object has no attribute 'get_type' 

다음과 같은 작용에 의해 트리거 :

def on_link_clicked(self): 
    self.a = self.linkEdit.displayText() 
    download_mango(self.a, self.path2) 

그리고 완전히 잃어 버렸습니다. PyQt4 문제 일 수도 있고 제 기능상의 문제 일 수도 있습니까?

감사합니다.

+0

코드를 붙여주십시오. download_mango 무엇입니까? – Froyo

답변

1

를 참조하십시오

"http://"or "https://"

누락되는

The string should work as an url and when I pass it through my first argument

외모 리 당신은 urlopen에 QString을 전달하고 있습니다. str()으로 감싸면 괜찮을 것입니다.

>>> url = QString('http://stackoverflow.com/questions/11121475') 
>>> urllib2.urlopen(url).read() 
### this generates your error ending with 
AttributeError: 'QString' object has no attribute 'get_type' 

>>> urllib2.urlopen(str(url)).read() 
### works 
+0

감사합니다. 나는 항상 QLineEdit이 이미 문자열과 같은 것을 전달했다고 생각했다. 이제는 같은 실수를 두 번 반복하지 않을 것입니다. –

+0

PySide를 사용하기 시작했습니다. "QString 및 QVariant와 같은 Python 개발자를위한 다른 쓸모없는 Qt 항목"이 제거 되었기 때문입니다. 면허증과 마찬가지로. –