Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Trusted Contributor
itcraps
Posts: 238
Registered: ‎12-26-2010
My Device: BlackBerry Z10
My Carrier: Telus
Accepted Solution

Tracking Signal Sender

I have an array multiple buttons created and assigned to specific function.

But I would like to know which button the user pressed. Any idea?

How should I implement the Signal and Slots

	for(int i=0;i<8;i++)
	{
		button[i]= Button::create();
                buttonContainer->add(button[i]);
QObject::connect(button[i], SIGNAL(clicked()), this, SLOT(doStuffs())); }

 

www.jackdevora.com
Please use plain text.
Trusted Contributor
marcelnijman
Posts: 117
Registered: ‎06-19-2012
My Device: PlayBook + Red Z10 + BB10 Dev Alpha C
My Carrier: none

Re: Tracking Signal Sender

[ Edited ]

Use QObject::sender() in your slot and cast the result to Button. If you first do "button[i].tag = i" then you can find out in the slot exactly which button was triggered. Unfortunately, you first need to subclass Button and include an integer tag value. I've already filed a feature request about this.

Please use plain text.
Trusted Contributor
itcraps
Posts: 238
Registered: ‎12-26-2010
My Device: BlackBerry Z10
My Carrier: Telus

Re: Tracking Signal Sender

Perfect, thanks!!!

 

www.jackdevora.com
Please use plain text.
Developer
dkonigs
Posts: 248
Registered: ‎07-25-2008
My Device: Bold 9900

Re: Tracking Signal Sender

You also may want to look up QSignalMapper:

http://qt-project.org/doc/qt-4.8/qsignalmapper.html

 

Its a utility class that's part of Qt, which is designed to help with this exact situation.

Please use plain text.
Trusted Contributor
marcelnijman
Posts: 117
Registered: ‎06-19-2012
My Device: PlayBook + Red Z10 + BB10 Dev Alpha C
My Carrier: none

Re: Tracking Signal Sender

Well, code doesn't become more beautiful this way. I still like my tag solution better. But thanks for telling us about it. It might come in handy sometime, especially in more complex cases that canot be handle with a simple tag value.

Please use plain text.
Developer
dkonigs
Posts: 248
Registered: ‎07-25-2008
My Device: Bold 9900

Re: Tracking Signal Sender

Actually, QSignalMapper is just a simpler way of implementing the tag approach.  The only difference is that you configure the tags in the QSignalMapper setup, instead of the buttons themselves, and the tag values are delivered right along with the signal parameters.  (so no need to check sender() or anything)

Please use plain text.
Developer
walkline
Posts: 82
Registered: ‎01-10-2013
My Device: Bold 9900
My Carrier: China Unicom

Re: Tracking Signal Sender

hey man, is there any details about this method? i got the same problem now and don't know how to do, thanks!~
Please use plain text.
Developer
walkline
Posts: 82
Registered: ‎01-10-2013
My Device: Bold 9900
My Carrier: China Unicom

Re: Tracking Signal Sender

did you solve your problem now?
Please use plain text.