PDA

View Full Version : signals and slot...can i select my option ?



salmanmanekia
7th August 2008, 09:46
hi..
i am writting this statement but it doesnt seem to work..


void Control::connectButton()
{
connect(accept,SIGNAL(clicked()),SIGNAL(buttonConn ected(0)));
}
..
connect(contrl,SIGNAL(buttonConnected(int)),traini ng,SLOT(informRecord(int)));
.
first my question are the above statement correct ?
my main purpose of putting 0 in the buttonConnected parameter is that that i can use it as option/choice i.e for selection
like i want to do also
connect(reject,SIGNAL(clicked()),SIGNAL(buttonConn ected(1)));
so if its accept buttonConnected() passes with 0 and if itz reject buttonConnected() passes with 1..

wysota
7th August 2008, 09:54
http://www.qtcentre.org/forum/faq.php?faq=qt_signalslot#faq_qt_signalslot_with_v alues

salmanmanekia
7th August 2008, 10:25
now i am trying this way but it also seems not working


void Control::connectButton()
{
if (connect(accept,SIGNAL(clicked()),this,SLOT(checkO ption(int))))
checkOption(0);
}
void Control::checkOption(int option)
{
if (option == 0)
emit buttonConnected(0);
}



..
connect(contrl,SIGNAL(buttonConnected(int)),traini ng,SLOT(informRecord(int)));
..

wysota
7th August 2008, 10:58
Qt should send a warning to your console in case something is wrong with the connection. So be sure to have console support activated and look for errors there. Did you remember about the Q_OBJECT macro and declaring appropriate symbols as slots and signals?

salmanmanekia
7th August 2008, 11:03
i just debug my code on eclipse and it shows me this warnings..


Current language: auto; currently c++
warning: QObject::connect: Incompatible sender/receiver arguments
QPushButton::clicked() --> Control::checkOption(int)

Quit (expect signal SIGINT when the program is resumed)

i am confused about one thing from very start that can the 'if' statement be placed in this way...i mean is it correct to place 'if' in this manner..

lyuts
7th August 2008, 11:20
The signature of the slot should be either the same as the signature of the signal, or shorter. So,


connect(accept,SIGNAL(clicked()),this,SLOT(checkOp tion(int))

is unacceptable.

spirit
7th August 2008, 11:29
that is what in a book "C++ GUI Programming with Qt 4, Second Edition
by Jasmin Blanchette; Mark Summerfield " is written:



To successfully connect a signal to a slot (or to another signal), they must have the same parameter types in the same order:

connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
this, SLOT(processReply(int, const QString &)));


Exceptionally, if a signal has more parameters than the slot it is connected to, the additional parameters are simply ignored:

connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
this, SLOT(checkErrorCode(int)));


If the parameter types are incompatible, or if the signal or the slot doesn't exist, Qt will issue a warning at run-time if the application is built in debug mode. Similarly, Qt will give a warning if parameter names are included in the signal or slot signatures.

wysota
7th August 2008, 12:08
I suggest you take a look at QSignalMapper, maybe you're trying to mimic what the class already does.

salmanmanekia
7th August 2008, 12:44
thanks every1...QSignalMapper solved it:cool: