<div dir="ltr"><div><p style="margin:1.2em 0px!important">Hi Jim,</p>
<p style="margin:1.2em 0px!important">I believe the issue is that the signal and slot are connected with the Direct Connection type. This causes the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">threadDone()</code> 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 <a href="http://qt-project.org/doc/qt-4.8/threads-qobject.html#signals-and-slots-across-threads" target="_blank">here</a> for all types of signal-slot connections.</p>
<p style="margin:1.2em 0px!important">I believe that it might work even with Direct Connection on Windows. However, it’s important to remember that <i>the fact that it works does not mean it’s correct</i>.</p>
<p style="margin:1.2em 0px!important">I don’t think this would cause the error, but I would also highly recommend switching to the <a href="http://qt-project.org/wiki/Signals_and_Slots_in_PySide#58416cc9bd5ea873816a3b0961146836" target="_blank">new syntax for signals and slots</a>. For quite complete guides on threading in Qt, see <a href="http://qt-project.org/doc/qt-4.8/thread-basics.html#gui-thread-and-worker-thread" target="_blank">Threading Basics</a> and <a href="http://qt-project.org/wiki/Threads_Events_QObjects" target="_blank">Threads, Events, and QObjects</a>.</p>
<p style="margin:1.2em 0px!important">I hope this helps. Let me know if it works for you.</p>
<p style="margin:1.2em 0px!important">Cheers,</p>
<div title="MDH:PGRpdj48ZGl2PjxkaXY+SGkgSmltLDxicj48YnI+PC9kaXY+SSBiZWxpZXZlIHRoZSBpc3N1ZSBp
cyB0aGF0IHRoZSBzaWduYWwgYW5kIHNsb3QgYXJlIGNvbm5lY3RlZCB3aXRoIHRoZSBEaXJlY3Qg
Q29ubmVjdGlvbiB0eXBlLiBUaGlzIGNhdXNlcyB0aGUgYHRocmVhZERvbmUoKWAgbWV0aG9kIHRv
IGJlIGludm9rZWQgaW4gdGhlIHdvcmtlcidzIHRocmVhZCwgd2hpY2gsIGF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zZWUgW1RocmVhZGluZyBCYXNpY3NdKGh0dHA6Ly9xdC1w
cm9qZWN0Lm9yZy9kb2MvcXQtNC44L3RocmVhZC1iYXNpY3MuaHRtbCNndWktdGhyZWFkLWFuZC13
b3JrZXItdGhyZWFkKSBhbmQgW1RocmVhZHMsIEV2ZW50cywgYW5kIFFPYmplY3RzXShodHRwOi8v
cXQtcHJvamVjdC5vcmcvd2lraS9UaHJlYWRzX0V2ZW50c19RT2JqZWN0cykuPGJyPjxicj48L2Rp
dj5JIGhvcGUgdGhpcyBoZWxwcy4gTGV0IG1lIGtub3cgaWYgaXQgd29ya3MgZm9yIHlvdS48YnI+
PGJyPkNoZWVycyw8YnI+" style="min-height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><br></div><div>--</div><div>Sean Fisk</div></div></div></div>
<br><div class="gmail_quote">On Sat, Dec 13, 2014 at 3:55 PM, Jim Byrnes <span dir="ltr"><<a href="mailto:jf_byrnes@comcast.net" target="_blank">jf_byrnes@comcast.net</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am running Ubuntu 12.04, PySide 1.2.2.<br>
<br>
I am just getting started with PySide and have been watching a series of<br>
video tutorials. In the video on threading there is the following program.<br>
<br>
from PySide.QtCore import *<br>
from PySide.QtGui import *<br>
import sys<br>
import showGui<br>
import time<br>
import showGui<br>
<br>
class MainDialog(QDialog, showGui.Ui_mainDialog):<br>
<br>
     def __init__(self, parent=None):<br>
         super(MainDialog, self).__init__(parent)<br>
         self.setupUi(self)<br>
<br>
         self.showButton.setText("Process")<br>
         self.connect(self.showButton, SIGNAL("clicked()"),<br>
self.processData)<br>
<br>
         self.workerThread = WorkerThread()<br>
         self.connect(self.workerThread, SIGNAL("threadDone(QString,<br>
QString)"), self.threadDone, Qt.DirectConnection)<br>
<br>
     def processData(self):<br>
         self.workerThread.start()<br>
         QMessageBox.information(self, "Done!", "Done.")<br>
<br>
     def threadDone(self, text, text2):<br>
         # Does not work.  Gives pixmaps error<br>
         #QMessageBox.warning(self, "Warning!", "Thread execution<br>
completed!")<br>
         # Works as expected<br>
         self.nameEdit.setText("Worker thread finished processing.")<br>
         print text<br>
         print text2<br>
<br>
class WorkerThread(QThread):<br>
<br>
     def __init__(self, parent=None):<br>
         super(WorkerThread, self).__init__(parent)<br>
<br>
     def run(self):<br>
         time.sleep(3)<br>
         self.emit(SIGNAL("threadDone(QString, QString)"), "Confirmation<br>
that the thread is finished.", "Another confirmation that the thread has<br>
been compledted.")<br>
<br>
app = QApplication(sys.argv)<br>
form = MainDialog()<br>
form.show()<br>
app.exec_()<br>
<br>
In the threadDone method uncommenting the QMessageBox line produces the<br>
following error message:<br>
<br>
QObject::setParent: Cannot set parent, new parent is in a different thread<br>
QPixmap: It is not safe to use pixmaps outside the GUI thread<br>
QPixmap: It is not safe to use pixmaps outside the GUI thread<br>
QPixmap: It is not safe to use pixmaps outside the GUI thread<br>
QPixmap: It is not safe to use pixmaps outside the GUI thread<br>
QPixmap: It is not safe to use pixmaps outside the GUI thread<br>
QPixmap: It is not safe to use pixmaps outside the GUI thread<br>
QPixmap: It is not safe to use pixmaps outside the GUI thread<br>
X Error: BadImplementation (server does not implement operation) 17<br>
   Major opcode: 20 (X_GetProperty)<br>
   Resource id:  0x0<br>
[xcb] Unknown sequence number while processing queue<br>
[xcb] Most likely this is a multi-threaded client and XInitThreads has<br>
not been called<br>
[xcb] Aborting, sorry about that.<br>
python2.7: ../../src/xcb_io.c:274: poll_for_event: Assertion<br>
`!xcb_xlib_threads_sequence_lost' failed.<br>
<br>
Process finished with exit code 134<br>
<br>
In the video the presenter is running Windows 8  and it worked for him.<br>
  Is this a known problem or am I just doing something wrong? I don't<br>
have a window machine to try it locally.<br>
<br>
Thanks,  Jim<br>
<br>
_______________________________________________<br>
PySide mailing list<br>
<a href="mailto:PySide@qt-project.org">PySide@qt-project.org</a><br>
<a href="http://lists.qt-project.org/mailman/listinfo/pyside" target="_blank">http://lists.qt-project.org/mailman/listinfo/pyside</a><br>
</blockquote></div></div>