[PySide] What if a slot is not decorated with @Slot()?
redstone-cold at 163.com
Sat Nov 19 03:47:38 CET 2022
The question originated from the issue :
In my project, self.sender() in the downloadFinished slot sometimes returns None instead of QNetworkReply, if comment the @Slot() ahead it seems to always return QNetworkReply - works well. The same issue also happened to the slot connected to the finished signal of QProcess. But the issue didn't happen for the PyQt5 version in my project. I reduced my senario to the following lite demo, but haven't seen the issue happened again, very strange !
Test environment : Python 3.9.13 on win11 64bit, latest PySide6.
from PySide6.QtCore import*
from PySide6.QtCore import Slot
from PySide6.QtCore import Signal
from PySide6.QtGui import*
from PySide6.QtWidgets import*
from PySide6.QtNetwork import*
def__init__(self, *args, **kwargs):
defdownloadProgress(self, bytesReceived, bytesTotal):
# er = reply.error()
# if er == QNetworkReply.NetworkError.NoError:
# bytes_string = reply.readAll()
# print(str(bytes_string, 'utf-8'))
# print("Error occured: ", er)
if __name__ =='__main__':
At 2022-11-18 19:02:29, "Christian Tismer-Sperling" <tismer at stackless.com> wrote:
>there is a configuration problem between Qt and PySide signals and
>slots. The Qt signals and slots are assigned once at compile time.
>On PySide, initialization is different since some things happen
>earlier or later. There *can* be situations constructed which go wrong,
>although doing that is difficult. You will not want to run into these
>problems by accident.
>Please believe me as one of the implementers:
>There is only one safe way to create reliable signals and slots.
>Use the decorator!
>Cheers - Chris
>On 16.11.22 15:18, Zhao Lee wrote:
>> I initially expect that the aim of the decorator @Slot() is to make
>> things easier like this
>> and without the decorator , you'd expect write a little more code like
>> But decorators in PySide become a little different. I know the decorator
>> can make the signal and slot connection a bit easier in PyQt in this way
>> */ @Slot(QModelIndex)/*
>> */ def on_downloadedView_doubleClicked(self, index) :/*
>> */ pass/*
>> But I still doubt the necessity of the decorator here if we write the
>> slot method name in this way. I wonder if it is possible to simplify the
>> mechanism in PySide like that in the above example of uwsgi without
>> requiring it is mandatory(In fact as I posted in last email, it seems
>> still ok without the decorator, although the doc states it is mandatory
>> to exist).
>Christian Tismer-Sperling :^) tismer at stackless.com
>Software Consulting : http://www.stackless.com/
>Strandstraße 37 : https://github.com/PySide
>24217 Schönberg : GPG key -> 0xFB7BEE0E
>phone +49 173 24 18 776 fax +49 (30) 700143-0023
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PySide