【发布时间】: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