[SOLVED]assign three slot to one signal.
-
Hi, i want assign three button's slot to a signal.
@
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QSignalMapper *signalmapper;
Ui::MainWindow *ui;
void test(int);signals:
void clickmee(int);
public slots:
void setclick1(int);
void setclick2(int);
void setclick3(int);private:
};
@
i do this in constructor:
@
signalmapper = new QSignalMapper(this);
signalmapper->setMapping(ui->pushButton, 10);
signalmapper->setMapping(ui->pushButton1, 10);
signalmapper->setMapping(ui->pushButton1, 10);
connect(signalmapper, SIGNAL(mapped(int)),this,SIGNAL(clickmee(int)));
@but when i run program in wrote:
@
QObject::connect: No such slot MainWindow::clickmee(int) in ..\Qsignal2\mainwindow.cpp:11
QObject::connect: (receiver name: 'MainWindow')
@
how can i assign slots to signal? -
Hi,
clickmee(int) is a signal not a slot
You can't assign slot to signals, only signals to slots and signals to signals.
-
how can i do that? i want to send parameter(line int) to button click event how can i do that? when i use setclick(int) the slot not working but when i using setclick() it worked. i want to pass a parameter.
-
You're not really clear...
What parameter line ?
Also:
@signalmapper = new QSignalMapper(this);
signalmapper->setMapping(ui->pushButton, 10);
signalmapper->setMapping(ui->pushButton1, 10);<-- why also 10 ?
signalmapper->setMapping(ui->pushButton1, 10);<-- twice ?
connect(signalmapper, SIGNAL(mapped(int)),this,SIGNAL(clickmee(int))); <-- Now a signal connected to a signal but is it really what you want ?
@ -
oh sorry your right. i edit that. but now how can i assign all button's click to this signal i.e when i click on every buttons clickmee(int) is called? clickmee(int) is implement in .moc file so i can't use from that.
-
It's done through the QSignalMapper.
But are you sure you want clickmee to be a signal ?
-
i want to do this
@void setclick1(int x)
{
if(x== 10)
{
....
}
else
{
...
}}
@
but this function not firing. -
i do that but that's not working this is my new code:
@
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void click(QString);private:
Ui::MainWindow *ui;
QSignalMapper *signalmaper;};@
.cpp
@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
signalmaper = new QSignalMapper(this);
signalmaper->setMapping(ui->pushButton, QString("dfdf"));
connect(signalmaper, SIGNAL(mapped(QString)),this, SLOT(click(QString)));
}void MainWindow::click(QString x)
{
ui->pushButton->setText(x);
}
@ -
id didn't know that. special thanks to you .
-
Nothing special here, look at the "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html#details documentation