我正在为项目使用PyQt.但并非突然间我得到了一个错误:
QPixmap: It is not safe to use pixmaps outside the GUI thread in PyQt
我在代码中的任何地方都没有使用QPixmap …请帮助.
class itemCheckBtn(QtGui.QDialog):
qApp = None;
okCallback = None;
def __init__(self,parent=None):
itemCheckBtn.qApp=None;
QtGui.QWidget.__init__(self, None)
self.ui = Ui_merchantPriceFrom();
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.itemCheckButton, QtCore.SIGNAL("clicked()"), self.submit)
def submit(self):
print "Hi";
主要的类是
class MyForm(QtGui.QMainWindow):
serverThreadObject = None;
qApp = None;
sock = None;
def __init__(self, qApp,parent=None):
MyForm.qApp=qApp;
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_bluwavemerchantmain()
self.ui.setupUi(self)
self.ui.server_connection_status_label.setText("Server Offline..");
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.connectUser )
QtCore.QObject.connect(self.ui.actionStart_Server, QtCore.SIGNAL("triggered()"), self.startServer);
QtCore.QObject.connect(self.ui.actionStop_Server, QtCore.SIGNAL("triggered()"), self.stopServerFromGui);
QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL("triggered()"), self.closeEventFromMenu);
QtCore.QObject.connect(self, QtCore.SIGNAL("triggered()"), self.closeEvent);
当我尝试从“ MyForm”类调用类“ itemCheckBtn”时,出现错误.
解决方法:
看起来您正在使用线程,并且您试图以某种方式尝试从主GUI线程以外的其他线程更改GUI(这是不允许的).这可能是间接发生的-例如,您的服务器线程在MyForm上调用了一个函数,该函数试图更新itemCheckBtn.即使该代码是MyForm的一部分,它仍在服务器线程中执行.相反,您需要使用某种线程安全机制来通知GUI线程已发生更改,并让其执行GUI工作. (请参阅http://doc.qt.nokia.com/4.6/threads-qobject.html)