473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

PyQt: Is signal / slot really working across threads?

Hello pyqt users,

i tried to use signal / slot across threads. With the following example I want
to emit a signal when the thread loop is entered. The connected slot is never
called. Why?

Any help is very welcome ...

Alexander

import time
import sys
import PyQt4
from PyQt4.QtCore import (QObject, QThread)
SIGNAL = PyQt4.QtCore.SIGNAL

class CancelableQtThread_(QThread):

def __init__(self):
QThread.__init__(self)
self.sigStarted = SIGNAL("sigStarted()")

def run(self):
print "Enter thread"
self.emit(self.sigStarted)
time.sleep(0.1)
print "Leave thread"

class TestSigSlot(QObject):

def __init__(self):
QObject.__init__(self)
self._thread = CancelableQtThread_()
self.connect(self._thread, self._thread.sigStarted, self.Called)
self._thread.start()

time.sleep(1.0)

def Called(self):
print "Called !"

if __name__ == "__main__":
obj = TestSigSlot()
May 29 '07 #1
2 3692
On Tuesday 29 May 2007 11:58 am, Alexander Eisenhuth wrote:
Hello pyqt users,

i tried to use signal / slot across threads. With the following example I
want to emit a signal when the thread loop is entered. The connected slot
is never called. Why?

Any help is very welcome ...

Alexander

import time
import sys
import PyQt4
from PyQt4.QtCore import (QObject, QThread)
SIGNAL = PyQt4.QtCore.SIGNAL

class CancelableQtThread_(QThread):

def __init__(self):
QThread.__init__(self)
self.sigStarted = SIGNAL("sigStarted()")

def run(self):
print "Enter thread"
self.emit(self.sigStarted)
time.sleep(0.1)
print "Leave thread"

class TestSigSlot(QObject):

def __init__(self):
QObject.__init__(self)
self._thread = CancelableQtThread_()
self.connect(self._thread, self._thread.sigStarted, self.Called)
self._thread.start()

time.sleep(1.0)

def Called(self):
print "Called !"

if __name__ == "__main__":
obj = TestSigSlot()
Signals across threads are implemented using the event loop. You don't have an
event loop running in your main thread - you don't even have a
QCoreApplication instance.

Phil
May 29 '07 #2
Ok, thanks.

Phil Thompson schrieb:
On Tuesday 29 May 2007 11:58 am, Alexander Eisenhuth wrote:
>Hello pyqt users,

i tried to use signal / slot across threads. With the following example I
want to emit a signal when the thread loop is entered. The connected slot
is never called. Why?

Any help is very welcome ...

Alexander

import time
import sys
import PyQt4
from PyQt4.QtCore import (QObject, QThread)
SIGNAL = PyQt4.QtCore.SIGNAL

class CancelableQtThread_(QThread):

def __init__(self):
QThread.__init__(self)
self.sigStarted = SIGNAL("sigStarted()")

def run(self):
print "Enter thread"
self.emit(self.sigStarted)
time.sleep(0.1)
print "Leave thread"

class TestSigSlot(QObject):

def __init__(self):
QObject.__init__(self)
self._thread = CancelableQtThread_()
self.connect(self._thread, self._thread.sigStarted, self.Called)
self._thread.start()

time.sleep(1.0)

def Called(self):
print "Called !"

if __name__ == "__main__":
obj = TestSigSlot()

Signals across threads are implemented using the event loop. You don't have an
event loop running in your main thread - you don't even have a
QCoreApplication instance.

Phil
May 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sibylle Koczian | last post by:
Still trying to learn PyQt from a book about several Python GUI toolkits, I seem to learn first what doesn't work. The following small script seems to work, but after closing the window I get the...
10
by: Peter | last post by:
I want to draw some lines on a widget. This works ok, but when I want to redraw, the old lines are still there. How do I clear or refresh the widget, so I can draw a new set of lines? Code...
3
by: Marcpp | last post by:
Hi, I'm introducing to program in python + pyqt. I have a main window that call a second window (to introduce a info with textedit) when press the second window button I need to return to the main...
7
by: Alex Gusarov | last post by:
Hello, I have strong .NET background with C# and want to do some familiar things from it with Python, but don't know how. For example, I created form in qt designer with QCalendarWidget, translated...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.