[PySide] Error on Ubuntu but not Windows

Jim Byrnes jf_byrnes at comcast.net
Sun Dec 14 18:13:43 CET 2014


On 12/13/2014 03:47 PM, Sean Fisk wrote:
> Hi Jim,
>
> I believe the issue is that the signal and slot are connected with the
> Direct Connection type. This causes the threadDone() method to be invoked
> in the worker’s thread, which, as stated by the error, results in unsafe
> behavior when accessing GUI elements. The default is Auto Connection for a
> reason — it usually auto-selects the best choice. See here
> <http://qt-project.org/doc/qt-4.8/threads-qobject.html#signals-and-slots-across-threads>
> for all types of signal-slot connections.
>
> I believe that it might work even with Direct Connection on Windows.
> However, it’s important to remember that *the fact that it works does not
> mean it’s correct*.
>
> I don’t think this would cause the error, but I would also highly recommend
> switching to the new syntax for signals and slots
> <http://qt-project.org/wiki/Signals_and_Slots_in_PySide#58416cc9bd5ea873816a3b0961146836>.
> For quite complete guides on threading in Qt, see Threading Basics
> <http://qt-project.org/doc/qt-4.8/thread-basics.html#gui-thread-and-worker-thread>
> and Threads, Events, and QObjects
> <http://qt-project.org/wiki/Threads_Events_QObjects>.
>
> I hope this helps. Let me know if it works for you.
>
> Cheers,
> --
> Sean Fisk

Sean,

Thanks for the explanation, it now works.  As to using the old style 
signals & slots syntax.  The videos have come out over a couple of years 
and the author says he will cover the new style signals & slots syntax 
in an upcoming video.

Regards,  Jim

> On Sat, Dec 13, 2014 at 3:55 PM, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>>
>> I am running Ubuntu 12.04, PySide 1.2.2.
>>
>> I am just getting started with PySide and have been watching a series of
>> video tutorials. In the video on threading there is the following program.
>>
>> from PySide.QtCore import *
>> from PySide.QtGui import *
>> import sys
>> import showGui
>> import time
>> import showGui
>>
>> class MainDialog(QDialog, showGui.Ui_mainDialog):
>>
>>       def __init__(self, parent=None):
>>           super(MainDialog, self).__init__(parent)
>>           self.setupUi(self)
>>
>>           self.showButton.setText("Process")
>>           self.connect(self.showButton, SIGNAL("clicked()"),
>> self.processData)
>>
>>           self.workerThread = WorkerThread()
>>           self.connect(self.workerThread, SIGNAL("threadDone(QString,
>> QString)"), self.threadDone, Qt.DirectConnection)
>>
>>       def processData(self):
>>           self.workerThread.start()
>>           QMessageBox.information(self, "Done!", "Done.")
>>
>>       def threadDone(self, text, text2):
>>           # Does not work.  Gives pixmaps error
>>           #QMessageBox.warning(self, "Warning!", "Thread execution
>> completed!")
>>           # Works as expected
>>           self.nameEdit.setText("Worker thread finished processing.")
>>           print text
>>           print text2
>>
>> class WorkerThread(QThread):
>>
>>       def __init__(self, parent=None):
>>           super(WorkerThread, self).__init__(parent)
>>
>>       def run(self):
>>           time.sleep(3)
>>           self.emit(SIGNAL("threadDone(QString, QString)"), "Confirmation
>> that the thread is finished.", "Another confirmation that the thread has
>> been compledted.")
>>
>> app = QApplication(sys.argv)
>> form = MainDialog()
>> form.show()
>> app.exec_()
>>
>> In the threadDone method uncommenting the QMessageBox line produces the
>> following error message:
>>
>> 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 sequence number while processing queue
>> [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:274: poll_for_event: Assertion
>> `!xcb_xlib_threads_sequence_lost' failed.
>>
>> Process finished with exit code 134
>>
>> In the video the presenter is running Windows 8  and it worked for him.
>>    Is this a known problem or am I just doing something wrong? I don't
>> have a window machine to try it locally.
>>
>> Thanks,  Jim
>>
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/pyside
>>
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>





More information about the PySide mailing list