0

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.

2 Answers2

1

You can get the button using sender() function. This function is used to get the senders in slots. Then you have to cast it to a class (in this case QPushButton) to be able to use it. If there is a need to pass another argument, please check out the answer of this question.

arsdever
  • 1,111
  • 1
  • 11
  • 32
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.