PDA

View Full Version : problem in sender()



wagmare
14th July 2009, 12:48
hi friends,

i got a small problem ..

i have a graphicsItem :- backButton (text: f7) and
a graphicsItem :- forwardButton(text f6)

so if the user clicks on backButton i am emitting a signal


connect(backitem6, SIGNAL(closeSignal()), this, SLOT(goMainPage()));

/*and slot*/
if(sender() == backitem){
/** operation for backitem**/
}else if(sender() == forwarditem){
/** operation for forward item **/
}


this works fine ...

now i try shortcuts f6 and f7 .. so i override keyevents on graphicsview()

now how can i integrate the keypress with that signal closeSignal()

means both clicking and pressing f7 i have to call goMainPage() ..
and sender() also i have to manage ..

please give me any suggestion to handle this situation ..

nish
14th July 2009, 12:54
just use a flag and set it when its the key event... check it before the sender() check

wagmare
14th July 2009, 12:58
like this ...


if(sender() == backitem7 || setFlag == 1)

nish
14th July 2009, 15:49
may be like this


void keyPressEvent()
{
if("key press is magic F7")
{
flag = true;
callSlot();
flag=false;
}
}

/*and slot*/
if(flag==true)
{
//key event
}
else if(sender() == backitem)
{
/** operation for backitem**/
}
else if(sender() == forwarditem)
{
/** operation for forward item **/
}

Lykurg
14th July 2009, 15:52
If you want that approach, then better use a parameter for your slot. If it is empty, check the sender().

nish
15th July 2009, 02:29
If you want that approach, then better use a parameter for your slot. If it is empty, check the sender().

ya i also thought that,, but if this slot is connected to other signals and used somewhere else than its a problem...we can have the default parameter,,, but i dont remeber if it can be connected to the signal of zero parameters, if it is so then its ok.

wagmare
15th July 2009, 06:19
ya i also thought that,, but if this slot is connected to other signals and used somewhere else than its a problem...we can have the default parameter,,, but i dont remeber if it can be connected to the signal of zero parameters, if it is so then its ok.

yes that slot goMainPage() is already connected to a void signal ...
so parameter slot() is not possible unless signal mapping ... but its very tedious process ..

its better to follow mr.death's way .... horror way ...

nish
15th July 2009, 06:25
its better to follow mr.death's way .... horror way ...
LOL.. i like when ppl follow me...muhahahahaha... long live the horror !

Lykurg
15th July 2009, 09:33
Hey, it's no problem:

public slots:
void test(int i = 0);
// works with
QObject::connect(button, SIGNAL(clicked()), this, SLOT(test())); // then with default '0'
//or
test(23); // with i == 23

nish
15th July 2009, 09:39
ya.. it really works!!!... time for me to go back to school :(

whats more instresting is that clicked(bool) connects with slot(int) :)

Lykurg
15th July 2009, 09:48
whats more instresting is that clicked(bool) connects with slot(int) :)
It's because a type cast is performed to find any matching function "test"

nish
15th July 2009, 09:50
It's because a type cast is performed to find any matching function "test"

thx for the info... btw isnt bool==int in c++?

Lykurg
15th July 2009, 09:59
thx for the info... btw isnt bool==int in c++?
As I know that was true in the early times of C (before C99). In C++ bool is a native data type with a lot of implicit conversions.

nish
15th July 2009, 10:04
Now i really need to go back to primary school..
thx