Results 1 to 14 of 14

Thread: problem in sender()

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem in sender()

    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
    Qt Code:
    1. connect(backitem6, SIGNAL(closeSignal()), this, SLOT(goMainPage()));
    2.  
    3. /*and slot*/
    4. if(sender() == backitem){
    5. /** operation for backitem**/
    6. }else if(sender() == forwarditem){
    7. /** operation for forward item **/
    8. }
    To copy to clipboard, switch view to plain text mode 

    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 ..
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in sender()

    just use a flag and set it when its the key event... check it before the sender() check

  3. The following user says thank you to nish for this useful post:

    wagmare (14th July 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in sender()

    like this ...
    Qt Code:
    1. if(sender() == backitem7 || setFlag == 1)
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

  5. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in sender()

    may be like this

    Qt Code:
    1. void keyPressEvent()
    2. {
    3. if("key press is magic F7")
    4. {
    5. flag = true;
    6. callSlot();
    7. flag=false;
    8. }
    9. }
    10.  
    11. /*and slot*/
    12. if(flag==true)
    13. {
    14. //key event
    15. }
    16. else if(sender() == backitem)
    17. {
    18. /** operation for backitem**/
    19. }
    20. else if(sender() == forwarditem)
    21. {
    22. /** operation for forward item **/
    23. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem in sender()

    If you want that approach, then better use a parameter for your slot. If it is empty, check the sender().

  7. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in sender()

    Quote Originally Posted by Lykurg View Post
    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.

  8. #7
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in sender()

    Quote Originally Posted by MrDeath View Post
    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 ...
    "Behind every great fortune lies a crime" - Balzac

  9. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in sender()

    its better to follow mr.death's way .... horror way ...
    LOL.. i like when ppl follow me...muhahahahaha... long live the horror !

  10. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem in sender()

    Hey, it's no problem:
    Qt Code:
    1. public slots:
    2. void test(int i = 0);
    3. // works with
    4. QObject::connect(button, SIGNAL(clicked()), this, SLOT(test())); // then with default '0'
    5. //or
    6. test(23); // with i == 23
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to Lykurg for this useful post:

    wagmare (15th July 2009)

  12. #10
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in sender()

    ya.. it really works!!!... time for me to go back to school

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

  13. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem in sender()

    Quote Originally Posted by MrDeath View Post
    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"

  14. #12
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in sender()

    Quote Originally Posted by Lykurg View Post
    It's because a type cast is performed to find any matching function "test"
    thx for the info... btw isnt bool==int in c++?

  15. #13
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem in sender()

    Quote Originally Posted by MrDeath View Post
    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.

  16. #14
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in sender()

    Now i really need to go back to primary school..
    thx

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  2. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38
  3. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.