Results 1 to 5 of 5

Thread: Proper PyQt5 signal & slot syntax

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Proper PyQt5 signal & slot syntax

    #ChangeSignals.increase.connect(self.signal_handle r)
    I am no PyQt expert, but in C++, you would need an instance of the ChangeSignals class as an argument of the connect() statement. Otherwise, how does connect() know which instance of the signalling class to connect to? Signals aren't broadcast, there must be explicit signal-slot or signal-signal connections between instances of the classes on each end. The only argument you supply is your signal_handler slot (and I assume that in PyQt connect() defaults the SignalWatchers instance on the receiving end (slot) to "self").
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    Oct 2019
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Proper PyQt5 signal & slot syntax

    Thank you for the response. I had also tried using an instantiated version of the class, but was still getting errors on connect.

    It turns out that the line 110 above:
    @pyqtSlot

    was causing the issue. I don't know why, but when I commented out this line everything worked! It looks like that decorator is only for non-class functions.

    Thanks!

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Proper PyQt5 signal & slot syntax

    Maybe it is my ignorance of PyQt and python in general, but where is the instance of ChangeSignals that forms the sending (signal) end of the increase() signal? I see you have defined a global variable named sig that is a ChangeSignals instance, but where is that used in the connect() statement?

    The only thing I can imagine is that ChangeSignals.increase.connect() must create a temporary instance of ChangeSignals that provides the signalling end and once __init__ exits this goes out of scope, gets destroyed, and the connection broken. Shouldn't this be "sig.increase.connect()" instead?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Oct 2019
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Proper PyQt5 signal & slot syntax

    No, you didn't miss anything. I went back to the version where I instantiated the class and used that signal, but I didn't update the code in my question. THEN I removed the pyqtSignal decorator.

    Sorry to throw you off!

  5. The following user says thank you to illuzioner1 for this useful post:

    d_stranz (3rd May 2020)

Similar Threads

  1. Replies: 0
    Last Post: 17th November 2015, 18:11
  2. PyQt4 Signal to PyQt5 Signal Convert?
    By mthnzbk in forum Qt Programming
    Replies: 3
    Last Post: 13th September 2015, 21:38
  3. Replies: 1
    Last Post: 28th February 2015, 16:20
  4. Replies: 2
    Last Post: 26th October 2013, 05:40
  5. Trouble with proper syntax for directorys
    By prophet0 in forum Newbie
    Replies: 2
    Last Post: 21st February 2012, 22:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.