PDA

View Full Version : Problem with unused parameter



devilj
4th July 2007, 02:50
I have a function:


QCheckBox *Window::createCheckBox(const QString &text, const QString &key)

{

QCheckBox *checkBox = new QCheckBox(text);

connect(checkBox, SIGNAL(stateChanged(2)), this, SLOT(addKeyword(key)));

connect(checkBox, SIGNAL(stateChanged(0)), this, SLOT(killKeyword(key)));

}

When I compile I receive:

warning: unused parameter ‘key’

Any thoughts?
Thanks

guilugi
4th July 2007, 07:16
Be careful, you're not using signals & slots in the good way !
You should check the docs to understand it better, and see some examples ;-)

You cannot connect signals with explicit parameters, you have to use QSignalMapper to achieve this.

Here, you can do something like that :


connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(addKeyword(int)));

You can only specify parameter types, not parameter values !

Guilugi.

wysota
4th July 2007, 08:37
When I compile I receive:

warning: unused parameter ‘key’


Omit the parameter name or use Q_UNUSED(key) to mark the variable as unused, preventing the warning from showing up.

And correct those signal/slot connections as advised.

devilj
4th July 2007, 10:23
Thanks for the response and your patients with a newbie....

So am I to gather that a signal doesn't neccessarily trigger a slot.

For instance just because SIGNAL(stateChanged()) emits a "2" doesn't mean my SLOT(addkeyword()) automatically triggers. In essence I need to "spy" on this signal and is this where SignalSpy and Signal Mapping come in? If so, is the result of the spying a variable that can be evaluated.

Thanks

jpn
4th July 2007, 10:25
Recommended reading: Signals and Slots (http://doc.trolltech.com/4.3/signalsandslots.html).

devilj
4th July 2007, 18:48
Ok, I see!

So really what I want to do is not rely on pre-defined slots and signals but create my own subclass wigets that will do what I want...more work, but MORE POWER!