I want to call a function function(QPushButton button)
when the user clicks a button.
I tried connect(myButton, SIGNAL(clicked()), this, SLOT(myFunction(myClass)));
but it does not work. I could do a separate function for slot but i need to create connections dynamicly for buttons created by user.
Asked
Active
Viewed 564 times
0
-
1Does this answer your question? [Qt 5 assign slot with parameters to a QPushButton](https://stackoverflow.com/questions/21150890/qt-5-assign-slot-with-parameters-to-a-qpushbutton) – Rinat Veliakhmedov Dec 27 '19 at 11:27
-
@RinatVeliakhmedov QSignalMapper is deprected. – Dec 27 '19 at 11:35
-
These days the best option is usually a lambda capturing the button. – Frank Osterfeld Dec 27 '19 at 12:01
2 Answers
0
I found a solution to my problem. @Rinat Veliakhmedov told me to check that question, but QSignalMapper is deprected and does not work with custom objects. I searched for a replacement for this method and found that theard. Solution with emit myFunction(myClass)
is perfect for my code.