Question: my table looks like this (all columns are nvarchar):

```
| col1 | col2 | col3 |
----------------------
|  ... | FFF8 | ...  |
|  ... |  -1  | ...  |
|  ... | FFF6 | ...  |
|  ... |  -9  | ...  |

```

If the value in the second column is not "-1" or "-9" i want to convert from hex to binary i. Any suggestions?

Answer: 
My preferred way of iterating over several widgets in pyqt is storing them as objects in lists.

```
myButtons = [self.ui.phase_scan_button, self.ui.etalon_scan_button,
             self.ui.mirror_scan_button, self.ui.gain_scan_button]
for button in myButtons:
    button.clicked.connect(lambda _, b=button: self.scan_callback(scan=b))

```

If you need the strings "phase", "etalon", "mirror" and "gain" separately, you can either store them in another list, or create a dictionary like

```
myButtons_dict = {"phase": self.ui.phase_scan_button,
                 "etalon": self.ui.etalon_scan_button,
                 "mirror": self.ui.mirror_scan_button,
                 "gain": self.ui.gain_scan_button}

for button in myButtons_dict:
    myButtons_dict[button].clicked.connect(lambda: _, b=button self.scan_callback(scan=b))

```

Note, how I use the lambda expression with solid variables that are then passed into the function `self.scan_callback`. This way, the value of `button` is stored for good.
As noted here : [Connecting slots and signals in PyQt4 in a loop](https://stackoverflow.com/questions/4578861/connecting-slots-and-signals-in-pyqt4-in-a-loop)
Using `functools.partial` is a nice workaround for this problem.

Have been struggling with same problem as OP for a day.