【问题标题】:pyqt with native python thread qpixmap and parent error带有本机python线程qpixmap和父错误的pyqt
【发布时间】:2016-12-25 22:52:57
【问题描述】:

我正在使用 python 本机线程和 pyqt 默认线程。当我想在本机线程中显示 qmessagebox 时,我的程序崩溃了。 这是我的代码:

.........
self.serverSoc.listen(5)
self.status="Server listening on %s:%s" % serveraddr
self.serverStatus = 1
thread.start_new_thread(self.listenClients, ())

def listenClients(self):
    while 1:
        clientsoc, clientaddr = self.serverSoc.accept()
        print("Client connected from %s:%s" % clientaddr)
        data = clientsoc.recv(self.buffsize)
        if data.startswith('%sendchatrequest%'):
            try:
                requestuser = data.rsplit(':', 1)[1]
                msg = "%s wanted to chat with you. Do you accept this?" %requestuser

                reply = QtGui.QMessageBox.question(self, 'Chat Request',
                                                   msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)

我得到了这个错误:

QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
X Error: BadImplementation (server does not implement operation) 17
Major opcode: 20 (X_GetProperty)
Resource id:  0x0
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
python2.7: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.

我该如何解决?非常感谢

【问题讨论】:

    标签: python multithreading pyqt


    【解决方案1】:

    Qt 要求所有的 GUI 操作都在主线程中完成。

    为什么不使用QTcpSocket 代替它很好地集成到 Qt 的主循环中而不需要线程?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      相关资源
      最近更新 更多