View Full Version : Qpushbutton clicked()

19th February 2011, 21:46
Hi, I want to know, how to send some parameters when QPushButton is clicked...I have array 8x8 of buttons, and i need for each button to send its x and y coordinates...like when button[4][5] is pressed, it calls function f(4,5), how can i do that ? Thanks

19th February 2011, 23:16
Have a look at QSignalMapper. It comes close your needs. Unfortunately, it allows only one parameter to be sent. But maybe, you can code your mapping as string, so a function f(const QString&) could be called as f("4,5") and inside f() you split the string into integers 4 and 5.

20th February 2011, 00:35
Thanks! That's exactly what I needed! ;)

20th February 2011, 03:03
A cleaner way to do this is to derive a new QPushbutton class that connects its own clicked() signal to an internal slot where a signal is emitted carrying the button's coordinates. Classes that connect to this signal don't need to know anything about the internal structure that emits it, and they don't have to parse a string to extract integers. The whole implementation requires just a few lines of code.