Krishna Raj
Krishna Raj

Reputation: 866

A slot for multiple buttons

I have two browse buttons in my application. I need to execute the function browseButtonClickHandler() for both the two buttons. but the problem is, how can I identify which button is clicked? I need to paste the browsed folder to a text field. create the signal and slot through the ui editor. I have assigned the function for both and its working too. But only difficulty is to identify the button. please help me.

Upvotes: 1

Views: 906

Answers (3)

emylia87
emylia87

Reputation: 66

Use QButtonGroup. Maybe this link could help.
http://doc.qt.io/qt-4.8/qbuttongroup.html#id

Upvotes: 2

Vinod Paul
Vinod Paul

Reputation: 359

Use QObject * QObject::sender () to know from where the signal originates.

You can also look into QSignalMapper. In the document, they have mentioned an example same as your problem

http://doc.qt.digia.com/4.6/qsignalmapper.html#details

Upvotes: 3

Gandras
Gandras

Reputation: 23

I would suggest to create a subclass of button class which has an index field and a virtual function that gives this index value. I assume that in browseButtonClickHandler() you get a pointer to the button, so cast it to your button subclass and get the index value.

Upvotes: 0

Related Questions