Results 1 to 7 of 7

Thread: signal -slot mechanism!! an interesting problem!!!

  1. #1
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default signal -slot mechanism!! an interesting problem!!!

    Is it wrong if I disconnect a connection
    before making it??
    I actually want to know whether a connection works "for the first time" when the control goes to it or it automatically works by itself from the very first attempt of signal triggering even if the connection is in a function/method which has not been executed till that moment of time when the signal is triggered??

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: signal -slot mechanism!! an interesting problem!!!

    That should not be happening, post some code (create a small compilable example that replicates the problem)

    Also, check if it's not Auto-Connection feature that connects your signals and slots.

  3. #3
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: signal -slot mechanism!! an interesting problem!!!

    Quote Originally Posted by Zlatomir View Post
    That should not be happening, post some code (create a small compilable example that replicates the problem)

    Also, check if it's not Auto-Connection feature that connects your signals and slots.
    I din't get what u want to convey............. r u saying that by default Qt connections have an auto-connect feature........... and thus disconnect can be done anywhere even if the function ,in which connection was there, is not executed till then???

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: signal -slot mechanism!! an interesting problem!!!

    The auto connection has some rules of naming for slots, to automatically connect them with the signals of QWidget in ui file.

    Auto connection does not happen for all (i was just pointing to check if it is not your case)

    LE: I don't think that it's ok to disconnect... maybe you should block signals when you don't want to execute the slots... but check careful (maybe your function gets called before you expect)

    Anyway, try to reproduce the problem with a small project, and post it here
    Last edited by Zlatomir; 5th August 2010 at 10:25.

  5. #5
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: signal -slot mechanism!! an interesting problem!!!

    k.....thanx ..........but I have sen that it is by default auotconnect itself...........here is some code which make my problem crystal clear!!!
    Qt Code:
    1. void functionName()
    2. {
    3. connect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),videoDisplayer,SLOT(playVideo()));
    4. connect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),this,SLOT(editButtonView()));
    5. connect(videoPlayerControls->processButton,SIGNAL(clicked()),this,SLOT(processVideo()));
    6. }
    7.  
    8.  
    9. void VideoPlayer::processVideo()
    10. {
    11. disconnect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),videoDisplayer,SLOT(playVideo())); //disconect called here as I have to use the slot play processed video here instead of play video
    12. connect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),videoDisplayer,SLOT(playProcessedVideo()));
    13. }
    To copy to clipboard, switch view to plain text mode 
    Here I have 2 cases:
    1. Only the "playPauseButton" is pressed
    2. ProcessButton is presed and then the playPauseButon is pressed

    Here I have to call a function playVideo() if only the playPauseButton is pressed(case 1).If the process button is pressed then I'll have to disconnect the connection made for the playPauseButton so that I can call the SLOT playProcessedVideo() on click of the playPauseButton..............plz help out with this!!!!!!

  6. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: signal -slot mechanism!! an interesting problem!!!

    You can do the connections in the constructor of the class (witch is best if you re-use the code after a while )

    And connect the clicked signal (of the Play button... with a slot called lets say Play)
    And within that slot just check the state of your checkable QPushButton:
    Qt Code:
    1. void VideoPlayer::Play() {
    2. if (ProcessButton.isChecked())
    3. playProcessedVideo(); //call the function to play processed
    4. else
    5. playVideo(); //call the function that just play
    6. }
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to Zlatomir for this useful post:

    qt_user (5th August 2010)

  8. #7
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: signal -slot mechanism!! an interesting problem!!!

    thanx a lot man......

Similar Threads

  1. signal -slot mechanism
    By qt_user in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2010, 18:34
  2. Replies: 5
    Last Post: 25th March 2010, 12:14
  3. When should I use signal/slot mechanism
    By Bryku in forum Newbie
    Replies: 3
    Last Post: 10th February 2010, 22:24
  4. slow signal-slot-mechanism
    By blm in forum Qt Programming
    Replies: 11
    Last Post: 28th October 2008, 17:10
  5. Interesting little Segfault w/r to signal/slot connection
    By Hydragyrum in forum Qt Programming
    Replies: 24
    Last Post: 12th September 2006, 19:22

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.