{
ui->setupUi(this);
int count = 0;
for (int t = 0; t < 10 ; t++)
{
count++;
buttonName.setNum(count);
buttonName.prepend("Button ");
theLayout->addWidget(theButton,count,1,1,1);
connect(theButton, SIGNAL(clicked()), theMapper, SLOT(map()));
theMapper->setMapping(theButton,buttonName);
}
centralWidget()->setLayout(theLayout);
connect(theMapper,
SIGNAL(mapped
(const QString &)),
this,
SIGNAL(clicked
(const QString &)));
}
{
qDebug() << text;
}
MainWindow::~MainWindow()
{
delete ui;
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
theMapper = new QSignalMapper(this);
QGridLayout *theLayout = new QGridLayout();
int count = 0;
for (int t = 0; t < 10 ; t++)
{
count++;
QString buttonName;
buttonName.setNum(count);
buttonName.prepend("Button ");
QPushButton *theButton = new QPushButton(buttonName);
theLayout->addWidget(theButton,count,1,1,1);
connect(theButton, SIGNAL(clicked()), theMapper, SLOT(map()));
theMapper->setMapping(theButton,buttonName);
}
centralWidget()->setLayout(theLayout);
connect(theMapper,SIGNAL(mapped(const QString &)),this,SIGNAL(clicked(const QString &)));
}
void clicked(const QString &text)
{
qDebug() << text;
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks