[PySide] Error on Ubuntu but not Windows

Sean Fisk sean at seanfisk.com
Sat Dec 13 22:47:40 CET 2014


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

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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20141213/1c7792fd/attachment.html>


More information about the PySide mailing list