Re: [PySide] What if a slot is not decorated with @Slot()?

2022-11-19 Thread Christian Tismer-Sperling

On 18.11.22 20:27, ic...@gmx.net wrote:

Hello Chris and others,

thanks for the insights. To be honest, I don't completely understand the
issues I might be facing when not using @Slot decorators. Furthermore, I
fear that there are a lot of code lines in my project which do not use
the decorator... (and it seems to work without any issues).

There is only one safe way to create reliable signals and slots.
Use the decorator!


If this statement is actually true, I'm starting to wonder why using
non-decorated python functions is at all possible in signal/slot
connections? Shouldn't there at least be a qWarning or a python warning
in these situations?

Kind Regards

Christoph

___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


It makes little sense to continue this conversation if you don't
trust my statements or I cannot explain the facts.

On the positive side: The problem is meanwhile gone for Qt 6.4
because the Qt people solved that sorting problem, lately.

Otherwise, you would get a warning that there is wrong ordering.
This was seen in https://bugreports.qt.io/browse/PYSIDE-2033 where
they used PySide 6.3.1 and got the warning

"""Signals and slots in QMetaObject 'SubclassObject' are not ordered 
correctly, this may lead to issues."""


This warning does not happen in 6.4, which means the sorting is ok now.

Solution for PySide
  6.3: Use decorators to be safe, but you get a warning if wrong.
  6.4: Problem gone. You should use the decorator for other reasons.

--
Christian Tismer-Sperling:^)   tis...@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

___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] What if a slot is not decorated with @Slot()?

2022-11-18 Thread Zhao Lee
Thanks Chris!
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*


import sys




classExample(QMainWindow):


def__init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.manager =QNetworkAccessManager(self)
self.reply2DownloadFileTuple={}


self.doRequest()


defdoRequest(self):


url 
='https://download-cdn.jetbrains.com/python/pycharm-professional-2022.2.3.exe'
request =QNetworkRequest(QUrl(url))
reply =self.manager.get(request)
self.reply2DownloadFileTuple[reply] =None
   


reply.finished.connect(self.downloadFinished)
reply.downloadProgress.connect(self.downloadProgress)#, 
Qt.QueuedConnection
   
@Slot(int,int)
defdownloadProgress(self, bytesReceived, bytesTotal):
reply =self.sender()
print(bytesReceived/bytesTotal,reply)



@Slot()
defdownloadFinished(self):
reply =self.sender()
print('reply---',reply)


ifnotisinstance(reply, QNetworkReply):
print('not QNetworkReply')
return
   


# er = reply.error()
# if er == QNetworkReply.NetworkError.NoError:


# bytes_string = reply.readAll()
# print(str(bytes_string, 'utf-8'))


# else:
# print("Error occured: ", er)
# print(reply.errorString())


# QCoreApplication.quit()



defmain():


app=QApplication(sys.argv)
win =Example()
win.show()
sys.exit(app.exec())



if __name__ =='__main__':
main()
At 2022-11-18 19:02:29, "Christian Tismer-Sperling"  
wrote:
>Hi Zhao,
>
>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
>> https://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html#notes 
>> 
>> and without the decorator , you'd expect write a little more code like
>> https://uwsgi-docs.readthedocs.io/en/latest/Signals.html?#timers 
>> 
>> 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:^)   tis...@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
___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] What if a slot is not decorated with @Slot()?

2022-11-18 Thread Tim Roberts

On 11/18/22 11:27 AM, ic...@gmx.net wrote:



If this statement is actually true, I'm starting to wonder why using
non-decorated python functions is at all possible in signal/slot
connections?


History.  Qt on Python predates decorators in Python.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] What if a slot is not decorated with @Slot()?

2022-11-18 Thread icfwm

Hello Chris and others,

thanks for the insights. To be honest, I don't completely understand the
issues I might be facing when not using @Slot decorators. Furthermore, I
fear that there are a lot of code lines in my project which do not use
the decorator... (and it seems to work without any issues).

There is only one safe way to create reliable signals and slots.
Use the decorator!


If this statement is actually true, I'm starting to wonder why using
non-decorated python functions is at all possible in signal/slot
connections? Shouldn't there at least be a qWarning or a python warning
in these situations?

Kind Regards

Christoph

___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] What if a slot is not decorated with @Slot()?

2022-11-18 Thread Christian Tismer-Sperling

Hi Zhao,

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
https://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html#notes 


and without the decorator , you'd expect write a little more code like
https://uwsgi-docs.readthedocs.io/en/latest/Signals.html?#timers 

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:^)   tis...@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

___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] What if a slot is not decorated with @Slot()?

2022-11-16 Thread Zhao Lee
I initially expect that the aim of the decorator @Slot() is to make things 
easier like this 
https://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html#notes
and without the decorator , you'd expect write a little more code like
https://uwsgi-docs.readthedocs.io/en/latest/Signals.html?#timers
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).
















At 2022-11-16 17:55:42, "Cristián Maureira-Fredes via PySide" 
 wrote:
>Hello,
>
>The answer can be found in
>https://code.qt.io/cgit/pyside/pyside-setup.git/tree/sources/pyside6/libpyside/dynamicqmetaobject.cpp#n557
>
>The main idea is to register Slots (and signals) at parsing time,
>before the connection is done.
>
>An old issue can be find here:
>https://bugreports.qt.io/browse/PYSIDE-315
>with some discussion as well.
>
>I hope that helps,
>Cheers
>
>On 11/16/22 06:47, Zhao Lee wrote:
>> The doc says 
>> :
>> 
>> It is really important to decorate each method declaration with a
>> @Slot(), in that way PySide6 knows internally how to register them
>> into Qt.
>> 
>> But the method used as the slot works well even without the @Slot() 
>> decorator , I wonder if there is a risk in doing so.
>> 
>> 
>> ___
>> PySide mailing list
>> PySide@qt-project.org
>> https://lists.qt-project.org/listinfo/pyside
>
>-- 
>Dr. Cristian Maureira-Fredes
>Senior R Manager
>
>The Qt Company GmbH
>Erich-Thilo-Str. 10
>D-12489 Berlin
>
>Geschäftsführer: Mika Pälsi,
>Juha Varelius, Mika Harjuaho
>Sitz der Gesellschaft: Berlin,
>Registergericht: Amtsgericht
>Charlottenburg, HRB 144331 B
>--
>___
>PySide mailing list
>PySide@qt-project.org
>https://lists.qt-project.org/listinfo/pyside
___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


Re: [PySide] What if a slot is not decorated with @Slot()?

2022-11-16 Thread Cristián Maureira-Fredes via PySide

Hello,

The answer can be found in
https://code.qt.io/cgit/pyside/pyside-setup.git/tree/sources/pyside6/libpyside/dynamicqmetaobject.cpp#n557

The main idea is to register Slots (and signals) at parsing time,
before the connection is done.

An old issue can be find here:
https://bugreports.qt.io/browse/PYSIDE-315
with some discussion as well.

I hope that helps,
Cheers

On 11/16/22 06:47, Zhao Lee wrote:
The doc says 
:


It is really important to decorate each method declaration with a
@Slot(), in that way PySide6 knows internally how to register them
into Qt.

But the method used as the slot works well even without the @Slot() 
decorator , I wonder if there is a risk in doing so.



___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


--
Dr. Cristian Maureira-Fredes
Senior R Manager

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin

Geschäftsführer: Mika Pälsi,
Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
--
___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside


[PySide] What if a slot is not decorated with @Slot()?

2022-11-15 Thread Zhao Lee
The doc says:

It is really important to decorate each method declaration with a @Slot(), in 
that way PySide6 knows internally how to register them into Qt.

But the method used as the slot works well even without the @Slot() decorator , 
I wonder if there is a risk in doing so.___
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside