简体   繁体   中英

SetText TypeError Pyqt4

I recently started creating a web browser when I started to run into some problems.

I defined the function

self.addressbar

As so:

    self.AddressBar = QtGui.QLineEdit(self.tab)
    self.AddressBar.setGeometry(QtCore.QRect(50, 20, 721, 31))
    self.AddressBar.setObjectName(_fromUtf8("AddressBar"))

I later defined

 self.Tab1Web

As so:

    self.Tab1Web = QtWebKit.QWebView(self.tab)
    self.AddressBar.setText(_fromUtf8(self.Tab1Web.url()))
    self.Tab1Web.setGeometry(QtCore.QRect(0, 70, 1171, 621))
    self.Tab1Web.setUrl(QtCore.QUrl(_fromUtf8("http://www.google.ca/?gfe_rd=cr&ei=GDbtWOjwM6WC8Qf-rI3QBA")))
    self.Tab1Web.setObjectName(_fromUtf8("Tab1Web"))

My problem is that I get the TypeError:

self.AddressBar.setText(_fromUtf8(self.Tab1Web.url()))
TypeError: setText(self, object): argument 1 has unexpected type 'QUrl'

The problem is that I do not know how to solve this. Thanks in advance!

Taken from

http://pyqt.sourceforge.net/Docs/PyQt4/qlineedit.html#setText

You should pass either a python string or pyqt QString.

Try:

self.AddressBar.setText(self.Tab1Web.url().toString())

It should do the trick....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM