[PySide] signal connection only works with lambda

Frank Rueter frank at ohufx.com
Thu Sep 1 06:00:13 CEST 2022


Hi Christian,

sorry for the delay.
Yes, the signal is declared in the class but not inside any function.
I had not used the @Slot decorator but tried it just now to no avail.
[image: image.png]
[image: image.png]
[image: image.png]

On Tue, Aug 30, 2022 at 7:21 PM Cristián Maureira-Fredes <
Cristian.Maureira-Fredes at qt.io> wrote:

>
>
> On 8/30/22 00:08, Frank Rueter wrote:
> > Hi all,
> >
>
> Hey Frank,
>
> > probably a pre-coffee hiccup:
> > I have this weird issue where my signal connection only works when
> > utilising lambda, even though the data type sent by the signal is
> > exactly what the receiving slot needs.
> > This is my code:
> >
> > In a worker class (QRunnable) I emit this signal
> > *    tasks_data_available = QtCore.Signal(list)
> > *
> >
>
> Just a sanity check:
> That's declared inside a class, but not inside any method, right?
>
> > In my main widget I connect it like this:
> > *        worker.tasks_data_available.connect(self.__prep_task_data)
> > *
> > the slot looks like this:
> > *    def __prep_task_data(self, task_list):
> > *
> > *        print(task_list)*
>
> Is this method decorated with a `@Slot(list)` ?
>
> @Slot(list)
> def __prep_task_data(elf, task_list):
>      ...
>
> > I have done this countless times, but for some reason in this case the
> > code never calls the slot when the QRunnable emits task_list.
> >
> > When I do this it works though:
> > *        worker.tasks_data_available.connect(lambda t:
> > self.__prep_task_data(t))
> > *
>
> This might be due to the lazy registration of the lambda as a Slot,
> without properly going through the Slot-registration process.
>
> > What am I missing? I should not have to use lambda in this case.
>
> It might be the missing @Slot,
> but let me know if that's not the case.
>
> > Cheers,
> > frank
>
>
> Cheers
>
> --
> Dr. Cristián Maureira-Fredes
> Senior R&D Manager
>
> The Qt Company GmbH
> Erich-Thilo-Str. 10
> D-12489 Berlin
>
> Geschäftsführer: Mika Pälsi,
> Juha Varelius, Jouni Lintunen
> Sitz der Gesellschaft: Berlin,
> Registergericht: Amtsgericht
> Charlottenburg, HRB 144331 B
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> https://lists.qt-project.org/listinfo/pyside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20220901/ddf68325/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 37926 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20220901/ddf68325/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 9915 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20220901/ddf68325/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 22074 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20220901/ddf68325/attachment-0005.png>


More information about the PySide mailing list