T
T
TemaKam2021-03-16 16:37:17
Python
TemaKam, 2021-03-16 16:37:17

How in the thread to wait for the completion of the function called by the signal, and get the value from this function?

I emit a signal in the stream

self.signal_deer_2fa.emit()
tfa_code = ... (из функции сигнала как-то)

then in this thread you need to continue working with this variable tfa_code

function, which is called when a signal is emitted:
def signal_deer_2fa_f(self):
        tfa = QtWidgets.QInputDialog.getText(self, 'Ввод 2фа.', 'Введите 2фа код:')
        return tfa # или без него

How can I wait on the thread until the user does something with the dialog box, and then get what he entered?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bbkmzzzz, 2021-03-17
@bbkmzzzz

the signal is emitted in the thread
the function bound to this signal is called
I need to wait in the thread until this function is executed and get the value from it

As soon as a signal is emitted, it enters the signal queue and will be processed as soon as possible.
QThread is a wrapper for threads that runs in QApplication, so it makes no sense to bind it with a slot.
Everything depends very much on the structure of the program
. There are several ways. Of the simple ones:
1. moveToThread(targetThread)
Create a QThread thread, empty, run it. We take a class and call the moveToThread method, all slots
of this class will be executed in thread
2. Queues
We create a queue (for example, queue.Queue), the thread continuously listens to the queue, when a task occurs there, picks it up and executes it.
Task - anything, the main thing is that the code knows what to do with it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question