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

发布于 2024-10-20 08:31:40 字数 1438 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情废物 2024-10-27 08:31:40

看起来您正在使用线程,并且不知何故您试图从主 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文