[Qt-interest] Need to show a dialog on click of QLabel (Scott Aron Bloom)

Scott Aron Bloom Scott.Bloom at sabgroup.com
Fri May 15 13:43:38 CEST 2009


> 
> Kamakshi Sivaraman wrote:
> >
> > Hi All,
> >
> > Thanks for your valuable suggestions it worked well.
> > But now I had another problem, I have around 300 - 500 labels,each
has
> > click event and the click event working well,
> > but all the labels are stored in array of QLabel. Now while clicking
I
> > want to know that the click event is generated by which
label-object.
> >
> > After clicking the label, in the slot function I unable to
recognize,
> > from which label-object the click is generated.
> > Do we have any provisions with QT that recognizes inside the slot
> > function that which label-object
> > is actually clicked like- storing the address of label-object etc.
> > Please suggest some thing upon this.
> >
> There are two possible solutions, both of which require only a single
slot.
> 	First, use QSignalMapper. The argument in the slot will be the
index of
> the button that sent the signal. Read about this in the documentation.
> 	Second, in the slot get a pointer to the button that sent the
signal
> with the statements:
> 	QButton *but = qobject_cast<QButton *>(sender());
> 	if(but != (QButton *)NULL) {
> 		code
> 	}
> It is important to use qobject_cast to cast the sender of the signal
as
> a type QButton. That way, if the sender happens not to be a QButton,
the
> cast will return NULL and you won't execute statements that might
cause
> a crash.

----------------
The sender() wont work, because the sender is the SignalMapper, not the
button.

Simply connect to the signal mappers mapped( QWidget * widget ) signal..
The widget sent back will be the button sent.. Then you can use
qobject-cast

Scott




More information about the Qt-interest-old mailing list