gpt4 book ai didi

python - 我没有在 PyQt 中使用 QPixmap。但我得到 QPixmap : It is not safe to use pixmaps outside the GUI thread in PyQt

转载 作者:行者123 更新时间:2023-11-28 16:52:47 28 4
gpt4 key购买 nike

我正在为一个项目使用 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)

关于python - 我没有在 PyQt 中使用 QPixmap。但我得到 QPixmap : It is not safe to use pixmaps outside the GUI thread in PyQt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5187608/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com