View Full Version : surprise why this simple statement doesnt work
salmanmanekia
28th July 2008, 08:30
Hi,
I want to disable my button on the click of it ...so i wrote this but it doesnt seem to work...
connect(navigate->recordButton,SIGNAL(clicked()),this,SLOT(setDisabl ed(TRUE)));
i am surprised ..why ?
salmanmanekia
28th July 2008, 08:54
arghh...i was using 'this' in the connect..my bad...
jpujolf
28th July 2008, 08:57
Hi,
I want to disable my button on the click of it ...so i wrote this but it doesnt seem to work...
connect(navigate->recordButton,SIGNAL(clicked()),this,SLOT(setDisabl ed(TRUE)));
i am surprised ..why ?
Didn't you receive an strange message when executing from Qt saying "cannot find SLOT setDisabled(TRUE)" ?
It may never work. Signal & Slot must have the same signature. Of course, these two methods have the same, but doesn't mean the same ( if is clicked but is not checked, setDisabled doesn't work as you want )
You can derive the QAbstractButton class, creating a new SLOT disableWhenPress ( bool Ignore ) and connect it like this :
connect(navigate->recordButton,SIGNAL(clicked()),this,SLOT(disableWh enPress()));
And it may work...
Another way of achieving this, perhaps a simpler one, could be connecting the pressed signal to an slot that does some stuff ( if you press the button to take some action, you have to program that action, haven't you ? ) and on the first line you disable the button manually :
button->setDisabled(true)
salmanmanekia
28th July 2008, 11:17
Didn't you receive an strange message when executing from Qt saying "cannot find SLOT setDisabled(TRUE)" ?
no, and i shouldnt be recieving this message because there is a slot named setDisabled in QWidget .http://doc.trolltech.com/4.4/qwidget.html#setDisabled
Of course, these two methods have the same, but doesn't mean the same ( if is clicked but is not checked, setDisabled doesn't work as you want )
i didnt understand what do you mean by that..:confused:
connect(navigate->recordButton,SIGNAL(clicked()),this,SLOT(disableWh enPress()));
I had already tried this way but this also did not worked..
Another way of achieving this, perhaps a simpler one, could be connecting the pressed signal to an slot that does some stuff ( if you press the button to take some action, you have to program that action, haven't you ? ) and on the first line you disable the button manually :
button->setDisabled(true)
This is very true but on the pressing of my button i am calling a different widget while as far button itself is concerned it is in a different widget ,so it is not true for my case....
THanks
jpujolf
28th July 2008, 11:31
no, and i shouldnt be recieving this message because there is a slot named setDisabled in QWidget
First I've to say sorry. I've wrote my answer while you write you answered yourself and I didn't see the difference you said ( I mean the "this" error )
i didnt understand what do you mean by that..:confused:
I think I haven't explained it very clear ( I don't speak/write English usually and perhaps that's the problem ).
I want to say that connecting a signal with an slot both with the same "aspect" ( both take a boolean parameter ) is possible, but the meaning of that value perhaps is not the desired or expected.
And of course I didn't know that you can call an SLOT changing parameter's values as you do. I thought that was an error.
Thanks to you, as we say in Spanish "Nunca te acostarás sin saber una cosa más" ( You'll never go to bed without learning something ) ;)
jacek
28th July 2008, 12:26
And of course I didn't know that you can call an SLOT changing parameter's values as you do. I thought that was an error.
It is an error. You were right, one can't specify parameter values or names in SLOT() and SIGNAL() macros.
wysota
28th July 2008, 12:42
It is an error. You were right, one can't specify parameter values or names in SLOT() and SIGNAL() macros.
As noted in the FAQ:
http://www.qtcentre.org/forum/faq.php?faq=qt_signalslot#faq_qt_signalslot_with_v alues
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.