PDA

View Full Version : signal -slot mechanism!! an interesting problem!!!



qt_user
5th August 2010, 09:46
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??

Zlatomir
5th August 2010, 10:40
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.

qt_user
5th August 2010, 11:07
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???

Zlatomir
5th August 2010, 11:17
The auto connection (http://doc.qt.nokia.com/qt-maemo-4.6/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect) 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 (http://doc.trolltech.com/4.6/qobject.html#blockSignals) 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

qt_user
5th August 2010, 11:28
k.....thanx ..........but I have sen that it is by default auotconnect itself...........here is some code which make my problem crystal clear!!!



void functionName()
{
connect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),videoDisplayer,S LOT(playVideo()));
connect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),this,SLOT(editBu ttonView()));
connect(videoPlayerControls->processButton,SIGNAL(clicked()),this,SLOT(processV ideo()));
}


void VideoPlayer::processVideo()
{
disconnect(videoPlayerControls->playPauseButton,SIGNAL(clicked()),videoDisplayer,S LOT(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,S LOT(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!!!!!!

Zlatomir
5th August 2010, 11:56
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:


void VideoPlayer::Play() {
if (ProcessButton.isChecked())
playProcessedVideo(); //call the function to play processed
else
playVideo(); //call the function that just play
}

qt_user
5th August 2010, 12:20
thanx a lot man......