How to call function with arguments using QThread [PySide6]
-
Is there any way to call QThread::create using PySide6? I want to call a function which uses some arguments in a new Thread. Is subclassing QThread the only way to do this right know?
Something like this:class Threader(QThread): def __init__(self, func, parent=None): super().__init__(parent) self.func = func self.arg = None def run(self): self.func(self.arg)
Then calling threader.arg before calling threader.start(). I feel like there has to be another way.
Thanks!
-
@Andresfe
I do not know about Qt6 and/or PySide6. But at Qt 5.10 this was introduced:to allow just that --- the passing of arbitrary arguments to a created
QThread
. Can you access that?[EDIT: Hmm, I see it is missing at https://doc.qt.io/qtforpython/PySide6/QtCore/QThread.html#static-functions]
Otherwise before that I think one had to do just as you say --- sub-class and store arguments for
run()
(e.g. as per accepted solutuon at https://stackoverflow.com/a/7864748/489865). -
Hi,
I would ask this question on the PySide mailing list. The method is also not available in PySide2 as it seems.