
Originally Posted by
prof.ebral
Wysota ... the Object doesn't even execute the reportThread method in your code, nor in mine. I'm trying to point that out to you. Like I said, you have a hard time reading.
I understand that it doesn't work for you, I don't know why. It works for me just fine and I'm sure it works for many other people because it is intended to work that way.
Even after the Object class is moved to the Thread class I still get the main thread's ID ... but for me the signal is not being caught by the Object's reportThread method."
You get the main thread ID's because you connect the timer's signal to the slot of an object that lives in main thread.
I just tried running the code you posted but it bails out with a syntax error (I'm using Python 3):
File "./code.py", line 11
print self, (QtCore.QThread.currentThreadId())
^
File "./code.py", line 11
print self, (QtCore.QThread.currentThreadId())
^
To copy to clipboard, switch view to plain text mode
After fixing those syntax errors (by putting print arguments in parenthesis) and running the code, I get this:
<__main__.Object object at 0x7fa7c3b50b00> <__main__.Thread object at 0x7fa7c3b50a70> 140358524008192
MainThread 140358524008192
<__main__.Thread object at 0x7fa7c3b50a70> 140358524008192
<__main__.Object object at 0x7fa7c3b50b00> 140358466680576
<__main__.Thread object at 0x7fa7c3b50a70> 140358524008192
<__main__.Object object at 0x7fa7c3b50b00> 140358466680576
You can see two slots are called -- one in Object (with thread id 576) and the other one in Thread (with thread id 192). That's the correct behaviour as described in Qt docs (PyQt can't possibly work differently because it's just a wrapper over Qt C++ classes). I don't know why you're getting no output for Object, the most obvious reason is that the worker thread is not started (or its event loop is not running).
A side note: I checked with Python2.7 and it works the same way as with Python3:
(<__main__.Object object at 0x7fa08aaf7d40>, <__main__.Thread object at 0x7fa08aaf7cb0>, 140327479097088L)
MainThread 140327479097088
(<__main__.Thread object at 0x7fa08aaf7cb0>, 140327479097088L(<__main__.Object object at 0x7fa08aaf7d40>, 140327422002944L)
)
(<__main__.Thread object at 0x7fa08aaf7cb0>, 140327479097088L)
(<__main__.Object object at 0x7fa08aaf7d40>, 140327422002944L)
(<__main__.Thread object at 0x7fa08aaf7cb0>, 140327479097088L)
(<__main__.Object object at 0x7fa08aaf7d40>, 140327422002944L)
Bookmarks