我没有在 PyQt 中使用 QPixmap。但我得到 QPixmap: It is not safe to use pixmaps Outside the GUI thread in PyQt
我正在使用 PyQt 进行项目。但并不是突然间我收到错误:
QPixmap:在 PyQt 中的 GUI 线程之外使用像素图是不安全的
我没有在代码中的任何地方使用 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”时出现错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在使用线程,并且不知何故您试图从主 GUI 线程以外的某个线程更改 GUI(这是不允许的)。这可能是间接发生的——例如,您的服务器线程调用 MyForm 上的一个函数,该函数尝试更新 itemCheckBtn。尽管代码是 MyForm 的一部分,但它仍然从服务器线程执行。相反,您需要使用某种线程安全机制来通知 GUI 线程发生了更改,并让它执行 GUI 工作。 (参见http://doc.qt.nokia.com/4.6/threads-qobject .html)
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)