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??
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.
Re: signal -slot mechanism!! an interesting problem!!!
Quote:
Originally Posted by
Zlatomir
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???
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
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!!!
Code:
void functionName()
{
connect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),videoDisplayer,SLOT(playVideo()));
connect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),this,SLOT(editButtonView()));
connect(videoPlayerControls->processButton,SIGNAL(clicked()),this,SLOT(processVideo()));
}
void VideoPlayer::processVideo()
{
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
connect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),videoDisplayer,SLOT(playProcessedVideo()));
}
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!!!!!!
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:
Code:
void VideoPlayer::Play() {
if (ProcessButton.isChecked())
playProcessedVideo(); //call the function to play processed
else
playVideo(); //call the function that just play
}
Re: signal -slot mechanism!! an interesting problem!!!