[Qt-interest] Need to show a dialog on click of QLabel (Scott Aron Bloom)
John McClurkin
jwm at nei.nih.gov
Fri May 15 13:29:08 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.
More information about the Qt-interest-old
mailing list