J
J
JRazor2014-07-19 22:38:30
Python
JRazor, 2014-07-19 22:38:30

Passing information to the main PyQt4 thread: how?

Dear colleagues. There was a problem: I wrote a module, made a GUI, wrote a Scrapy spider, but I can’t pass information to the main GUI thread.
When developing, I used the SimpleThread module ( habrahabr.ru/post/125699 ) and programmed the button into another thread (so that Gui does not freeze during operation). But I can't pass information to QLabel.
Of course, I used SLOT-SIGNAL:

from PyQt4 import QtCore
 
@QtCore.pyqtSlot(object)
def saySomething(stuff):
    print stuff
 
class Communicate(QtCore.QObject):
    speak = QtCore.pyqtSignal(object)
 
someone = Communicate()
someone.speak.connect(saySomething)
someone.speak.emit("Test text!")

The signal is sent (if you just write print text, the text will be displayed, but self.ui.output.setText(text) does not work. Can anyone tell me why?
How to send a signal with a parameter to the main GUI thread?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hlamer, 2014-07-24
@hlamer

You saved the code that works, but you didn't save the code that doesn't actually work.
Try to make a basic case without simple_thread first: An object of a class inherited from QThread, the signal is sent from the run () method. QLabel.setText receives the signal. This all happens in a running application (after app.exec_())
In principle, signal-slots between threads in Qt work fine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question