Python QLineEdit和自定义函数不兼容

Python QLineEdit和自定义函数不兼容,python,string,pyqt4,Python,String,Pyqt4,我试图用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

我试图用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问题还是我的功能有问题

谢谢你的帮助。

赛尔夫。a不见了

http://”或“https://

试一试


请参见

您没有发布足够的代码来证明您的声明

当我通过第一个参数传递该字符串时,该字符串应作为url使用

看起来您正在向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

请粘贴您的代码。什么是芒果?谢谢!我一直认为QLineEdit已经像字符串一样传递了东西。现在我不再重复同样的错误两次了,我开始使用PySide是因为它删除了“QString和其他对python开发人员无用的Qt东西,比如QVariant”。我也更喜欢驾照。
>>> 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