I am not using QPixmap, in PyQt. but I get QPixmap: It is not safe to use pixmaps outside the GUI thread in PyQt

こ雲淡風輕ζ 提交于 2019-12-10 20:38:52

问题


I am using PyQt for a project. But not all of a sudden I am getting an error:

QPixmap: It is not safe to use pixmaps outside the GUI thread in PyQt

I am not using QPixmap anywhere in my code... please help.

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";

The main class is

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);

i am getting the error when I try to call the class "itemCheckBtn" from the "MyForm" class.


回答1:


It looks like you are using threads, and somehow you are trying to change the GUI from some thread other than the main GUI thread (this is not allowed). This could be happening somewhat indirectly--for example your server thread calls a function on MyForm, which tries to update the itemCheckBtn. Even though the code is part of MyForm, it is still being executed from the server thread. Instead, you need to use some thread-safe mechanism to inform the GUI thread that a change has occurred, and let it do the GUI work. (see http://doc.qt.nokia.com/4.6/threads-qobject.html)



来源:https://stackoverflow.com/questions/5187608/i-am-not-using-qpixmap-in-pyqt-but-i-get-qpixmap-it-is-not-safe-to-use-pixmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!