0

I am converting a code from PyQt4 to PyQt5 I encounter two difficulties, first that a signal dictionary is created with the name of the signal and the signal

MY_SIGNALS = {
     'clicked': SIGNAL ('clicked'),
     'currentIndexChanged': SIGNAL ('currentIndexChanged')
     ...
     }

Second, in a function I receive a widget and a signal name in such a way that

def connect_actions (received_action, my_control):
     ...
     connect (my_control, MY_SIGNALS [received_action], function_exec)

One solution is to check the received string and the widget

if my_control is QtWidgets.QPushButton:
    if received_action is "clicked":
         my_pushbutton.clicked.connect (function_exec)

but there are dozens of widgets and tokens, is there a way to adapt the code in such a way to assign a token by name like in PyQt4?

How can I adapt this code?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Habitante5079
  • 11
  • 1
  • 2

1 Answers1

0

A possible solution is to use getattr:

def connect_actions(received_action, my_control):
     getattr(my_control, received_action).connect(function_exec)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241