how to know which is the class that sends the signal in qt ?
My question is about how to know which is the class that sends the signal because what i want to do is specified to the class that has sent the signal
is it possible to do that ?
this is a prototype of what i intend to do
Code:
if (signal comes from class 1)
{do specified actions }
else if (comes from class 2)
{do something else }
Thanks
Re: how to know which is the class that sends the signal in qt ?
To answer yor question yes, use QObject::sender() and then cast it in to whatever class you want.
But basing the logic on the sending object is not considered as a good design, so try not to base your logic on the sender.
May be you could use QSignalMapper instead and base your logic on the formal slot parameter.
Re: how to know which is the class that sends the signal in qt ?
i know the method QSignalMapper but don't konw how to use it with this code
Code:
connect( ui->welcome, SIGNAL(changeStackedWidgetIndex(int)),
ui->stackedWidget, SLOT(setCurrentIndex(int)) );
connect( ui->credentials, SIGNAL(changeStackedWidgetIndex(int)),
ui->stackedWidget, SLOT(setCurrentIndex(int)) );
connect( ui->config, SIGNAL(changeStackedWidgetIndex(int)),
ui->stackedWidget, SLOT(setCurrentIndex(int)) );
connect( ui->syncwindow, SIGNAL(changeStackedWidgetIndex(int)),
ui->stackedWidget, SLOT(setCurrentIndex(int)) );
connect( ui->loaduser, SIGNAL(changeStackedWidgetIndex(int)),
ui->stackedWidget, SLOT(setCurrentIndex(int)) );
Re: how to know which is the class that sends the signal in qt ?
Why would you want to use it with this code?
Re: how to know which is the class that sends the signal in qt ?
Code:
connect(ui->welcome, SIGNAL(changeStackedWidgetIndex()), signalMapper, SLOT(map()) );
signalMapper->setMapping(ui->welcome, 0);
connect(ui->credentials, SIGNAL(changeStackedWidgetIndex()), signalMapper, SLOT(map()) );
signalMapper->setMapping(ui->credentials, 1);
connect(ui->config, SIGNAL(changeStackedWidgetIndex()), signalMapper, SLOT(map()) );
signalMapper->setMapping(ui->config, 2);
connect(ui->syncwindow, SIGNAL(changeStackedWidgetIndex()), signalMapper, SLOT(map()) );
signalMapper->setMapping(ui->syncwindow, 3);
connect(ui->loaduser, SIGNAL(changeStackedWidgetIndex()), signalMapper, SLOT(map()) );
signalMapper->setMapping(ui->loaduser, 4);
connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(setCurrentIndex(int)));