Qt-interest Archive, May 2007
how can i get more info when some qaction's activated() signal emits?
Message 1 in thread
hi,
i got this strange question
in my apps, user will dynamically create some subPopupMenu and/or
qaciton in one menu
( thinking add bookmarks )
while( ..... ){
..............
QAction *newAct=new QAction(...........................);
connect(newAct,SIGNAL(activated()),this,SLOT( newActClickedslot()));
newAct->addTo(menu);
...........
}
the num of newAct is not fixed, so i connect all newActs to newActClickedslot();
but question is i cannot distinguish which newAct clicked,
( just thinking as bookmarks, when user activates certain bookmark,how
to distinguish then? )
regards
--
[ signature omitted ]
Message 2 in thread
jiang jefix schrieb:
> but question is i cannot distinguish which newAct clicked,
> ( just thinking as bookmarks, when user activates certain bookmark,how
> to distinguish then? )
That's what QSignalMapper is for.
Martin
--
[ signature omitted ]
Message 3 in thread
> > but question is i cannot distinguish which newAct clicked,
> > ( just thinking as bookmarks, when user activates certain bookmark,how
> > to distinguish then? )
>
> That's what QSignalMapper is for.
QActionGroup might be handy as well.
--
[ signature omitted ]
Message 4 in thread
J-P Nurmi wrote:
>> > but question is i cannot distinguish which newAct clicked,
>> > ( just thinking as bookmarks, when user activates certain bookmark,how
>> > to distinguish then? )
>>
>> That's what QSignalMapper is for.
>
> QActionGroup might be handy as well.
>
You can also get a pointer to the QAction that emitted a signal within a
slot with the expression:
QAction *act = qobject_cast<QAction *>(sender());
You can then query the pointer to get specific information.
--
[ signature omitted ]
Message 5 in thread
On 11.05.07 08:55:21, John McClurkin wrote:
> J-P Nurmi wrote:
> >>> but question is i cannot distinguish which newAct clicked,
> >>> ( just thinking as bookmarks, when user activates certain bookmark,how
> >>> to distinguish then? )
> >>
> >>That's what QSignalMapper is for.
> >QActionGroup might be handy as well.
>
> You can also get a pointer to the QAction that emitted a signal within a slot
> with the expression:
> QAction *act = qobject_cast<QAction *>(sender());
> You can then query the pointer to get specific information.
That only works of course when the slot wasn't called directly. So a
check that act != 0 should be added there.
Andreas
--
[ signature omitted ]
Message 6 in thread
yes,this is just what i need
thanks
--
[ signature omitted ]