[英]QLineEdit and custom function incompatibility
我正在嘗試使用Python和PyQt4完成我的項目,並且在通過我創建的函數傳遞QLineEdit變量時遇到問題。 該字符串應作為url使用,當我通過第一個參數(嘗試讀取url並獲取其內容)傳遞該字符串時,會引發以下錯誤:
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問題或我的功能有問題嗎?
我感謝您的幫助。
您沒有發布足夠的代碼來證明您的陳述的合理性,
該字符串應作為url使用,當我通過第一個參數傳遞該字符串時
看起來您正在將QString傳遞給urlopen。 只需將其包裝在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
self.a丟失
“ http:// ”或“ https:// ”
嘗試
download_mango("http://"+self.a,self.path2)
參見http://www.nullege.com/codes/search/urllib2.Request.get_type
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.