我没有在 PyQt 中使用 QPixmap.但我得到了 QPixmap:在 PyQt 的 GUI 线程之外使用像素图是不安全的 [英] I am not using QPixmap, in PyQt. but I get QPixmap: It is not safe to use pixmaps outside the GUI thread in PyQt

查看:144
本文介绍了我没有在 PyQt 中使用 QPixmap.但我得到了 QPixmap:在 PyQt 的 GUI 线程之外使用像素图是不安全的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中使用 PyQt.但并非突然间我收到一个错误:

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

QPixmap:在 PyQt 的 GUI 线程之外使用像素图是不安全的

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

我没有在代码中的任何地方使用 QPixmap...请帮忙.

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

主类是

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 getting the error when I try to call the class "itemCheckBtn" from the "MyForm" class.

推荐答案

看起来您正在使用线程,并且以某种方式试图从主 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)

这篇关于我没有在 PyQt 中使用 QPixmap.但我得到了 QPixmap:在 PyQt 的 GUI 线程之外使用像素图是不安全的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆