Based on this answer, I try to get the name of the QPushButton
when the button is clicked. I don't have an error but when I try to print the name, I get nothing.
Here my code:
def add_btn(self):
for i in range(0, 10):
for j in range(1):
self.btn = QPushButton("btn_%i" % i)
self.btn_area.addWidget(self.btn,i,j)
self.btn.clicked.connect(lambda: self.dostuff(self.btn))
def dostuff(self, btn):
self.btn = btn
name_btn_clicked = self.btn.objectName()
print("Name: ",name_btn_clicked)
The result (empty string):
Name: