PDA

View Full Version : qSignalMapper gets no output



saman_artorious
29th July 2012, 11:04
I don't know why when I click the two radio buttons no text is output via QSignalMapper:

class:


private slots:
void clicked(QString text);
private:
void set_mappings();

Ui::SettingsWindow *ui;
QSignalMapper *mapper;



constructor:



mapper = new QSignalMapper(this);
set_mappings();


inside set_mappings() and clicked()


void SettingsWindow::set_mappings()
{
connect(ui->general_radio_backLightOff, SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(ui->general_radio_backLightOff,"general_radio_backLightOff");
connect(ui->general_radio_backLightOn, SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(ui->general_radio_backLightOn,"general_radio_backLightOn");

connect(mapper,SIGNAL(mapped(QString)),this,SIGNAL (clicked(QString)));
}


void SettingsWindow::clicked(QString text)
{
qDebug() << text;
}

wysota
29th July 2012, 11:07
Radio buttons are usually used with the toggled(bool) signal. Then you won't need that signal mapper at all (it should work with the toggled() signal as well).

saman_artorious
29th July 2012, 11:26
Radio buttons are usually used with the toggled(bool) signal. Then you won't need that signal mapper at all (it should work with the toggled() signal as well).

Negative.toggle takes boolean as input, which is not of the same type as for the map() slot.
The purpose I intended to use signalMapper is to get the value and object name of the radio button clicked, so accordingly I can call the relevant function or slot using the acquired values from mapper.

amleto
29th July 2012, 12:20
there is no signal

mapped(QString)

saman_artorious
29th July 2012, 12:46
there is no signal

mapped(QString)

you mind taking a look at the code above n tell me what exactly is wrong with it please. what is mapped(QString) ? there is so such slot n signal in the code.

amleto
29th July 2012, 13:03
there is so such slot n signal in the code.
Yes there is.

you mind taking a look at the code above n tell me what exactly is wrong with it please.
You are trying to connect to the afore mentioned signal but there does not exist any such signal on signal mapper.

saman_artorious
29th July 2012, 14:14
there is so such slot n signal in the code.
Yes there is.

you mind taking a look at the code above n tell me what exactly is wrong with it please.
You are trying to connect to the afore mentioned signal but there does not exist any such signal on signal mapper.

i'm confused, the signal you mentioned is a defined signal of qsignalmapper, which is connected to the clicked(QString ) signal.

connect(mapper,SIGNAL(mapped(QString)),this,SIGNAL (clicked(QString)));

i don't know how this code shall be modified to get the output, could you show me please

amleto
29th July 2012, 14:23
read the docs more carefully. It does not have the signal you are using - the signature is different (const QString & != QString).

saman_artorious
31st July 2012, 08:07
read the docs more carefully. It does not have the signal you are using - the signature is different (const QString & != QString).

I did try, it fails:


void SettingsWindow::set_mappings()
{
connect(ui->general_radio_backLightOff, SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(ui->general_radio_backLightOff,"general_radio_backLightOff");
connect(ui->general_radio_backLightOn, SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(ui->general_radio_backLightOn,"general_radio_backLightOn");

connect(mapper,SIGNAL(mapped(const QString &)),this,SIGNAL(clicked(const QString &)));
}




signals:
void clicked(const QString &text);

amleto
31st July 2012, 08:42
well then I guess the only thing left to do is read my sig.

saman_artorious
31st July 2012, 09:00
well then I guess the only thing left to do is read my sig.
that's not a good idea : (