Pyqt5运行pyqt4各种错误解决方法汇总

1.NameError: name 'QApplication' is not defined

from PyQt5.QtWidgets import QApplication

2.NameError: name 'QLabel' is not defined

from PyQt5.QtWidgets import *

3.NameError: name 'QDialog' is not defined

from PyQt5.QtWidgets import QInputDialog, QLineEdit, QDialog

4.AttributeError: 'Form' object has no attribute 'connect'

In PyQt5 you need to use the connect() and emit() methods of the bound signal directly, e.g. instead of:

self.emit(pyqtSignal('add_post(QString)'), top_post)
self.connect(self.get_thread, pyqtSignal("add_post(QString)"), self.add_post)
self.connect(self.get_thread, pyqtSignal("finished()"), self.done)

use:

self.add_post.emit(top_post)
self.get_thread.add_post.connect(self.add_post)
self.get_thread.finished.connect(self.done)

https://stackoverflow.com/questions/41848769/pyqt5-object-has-no-attribute-connect

5.NameError: name 'unicode' is not defined

Python 3 renamed the unicode type to str, the old str type has been replaced by bytes.

猜你喜欢

转载自blog.csdn.net/rosefun96/article/details/79440064