Results 1 to 7 of 7

Thread: Reconnect signal/slot between two objects

  1. #1
    Join Date
    Aug 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Reconnect signal/slot between two objects

    Greetings,
    I have stumbled on a strange problem. I have multiple QGraphicsScene objects from which signals from only one should be connected to slots of some buttons on user interface. So when I change scenes I disconnect old scene and connect new scene. So far it works. But if I return to previous scene (back button), signal/slot connections do not function anymore. Is there something in QObject::connect and QObject::disconnect that I am missing?
    Thank you.

    Regards,
    MadBear

  2. #2
    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: Reconnect signal/slot between two objects

    what does the "back button"? did you also change the connections?

  3. #3
    Join Date
    Aug 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reconnect signal/slot between two objects

    Greetings,
    Thank you for your reply. Ok buttons that move between scenes do (in a nutshell):
    Qt Code:
    1. disconnect(currentScene,0,0,0);
    2. currentScene=nextScene(); //or previousScene()
    3. connect(currentScene,SIGNAL(),control,SLOT());
    To copy to clipboard, switch view to plain text mode 

    This happens every time I press button (OK actually there are forward and back button). The problem arises when I return to scene that was already connected to control. Then signal/slot connection does not work.

    Regards,
    MadBear

  4. #4
    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: Reconnect signal/slot between two objects

    if forward works and backwards is not, then you have an error somewhere in your code. (The scene doesn't get blocked all the time if you once disconnect it.) Did you use the same functions to connect for both cases. Are you using a valid pointer to the "previous scene"?

  5. #5
    Join Date
    Aug 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reconnect signal/slot between two objects

    Greetings,
    Thank you for your reply. Now to answer your question. I use this disconnect and connect on forward and back buttons. And pointers are valid (I store them in QList). I disconnect with pointer to scene that was currently active, then I put pointer to next scene (or previous) into variable currentScene and connect this new current scene to slot.
    I hope I can show this in a pseudocode:

    Qt Code:
    1. void init()
    2. {
    3. currentScene=list.someScene();
    4. connect(currentScene,SIGNAL(),control,SLOT());
    5. }
    6. ...
    7. ...
    8. ...
    9. void forwardButtonClick()
    10. {
    11. disconnect(currentScene,0,0,0);
    12. currentScene=list.nextScene();
    13. connect(currentScene,SIGNAL(),control,SLOT());
    14. }
    15.  
    16. void backButtonClick()
    17. {
    18. disconnect(currentScene,0,0,0);
    19. currentScene=list.previousScene();
    20. connect(currentScene,SIGNAL(),control,SLOT());
    21. }
    To copy to clipboard, switch view to plain text mode 

    Like I already said, the problem arises when I click for instance forwardButton and then backButton. After that signals do not work anymore (even if I would press forward again).

    Regards,
    MadBear

  6. #6
    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: Reconnect signal/slot between two objects

    Well, the pseudo code does not help very much, since in theory it should work. So can you provide a minimal compilable example which reproduce your problem?

  7. #7
    Join Date
    Aug 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reconnect signal/slot between two objects

    Greetings,
    Thank you for your help. I must admit, that this problem showed me again, that stupid errors are sometimes most difficult to detect. There was another signal in the scene which was created in scene constructor (it was simple signal/slot connection on itself that in turn emits correct signals to the outside (not the most elegant solution)) and it was deleted with disconnect(scene,0,0,0). I completely forgot about that signal.
    Thank you again for your help and my apologies for waste of your time.

    Regards,
    MadBear

Similar Threads

  1. Signal connected to slot (or signal)
    By Althor in forum Newbie
    Replies: 2
    Last Post: 6th July 2010, 11:00
  2. Replies: 4
    Last Post: 2nd December 2008, 17:44
  3. Replies: 1
    Last Post: 8th November 2007, 18:11
  4. signal/slot
    By popai in forum Qt Programming
    Replies: 16
    Last Post: 1st August 2007, 14:56
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 19:52

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.