Code: Alles auswählen
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow), mapper(NULL)
{
ui->setupUi(this);
mapper = new QSignalMapper(this);
foreach(QLineEdit *le, this->findChildren<QLineEdit *>() )
{
if ( le->objectName().startsWith("input", Qt::CaseInsensitive) )
{
qDebug() << "Connect Signal mapper..." << (connect(le, SIGNAL(textChanged(QString)), mapper, SLOT(map())) ? "hat geklappt":"das war wohl nix");
mapper->setMapping(le, le);
}
}
qDebug() << "Connect mapper to function..." << (connect(mapper, SIGNAL(mapped(QWidget*)), this, SLOT(on_aTxtChanged(QWidget*))) ? "hat geklappt":"das war wohl nix");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_aTxtChanged(QWidget *caused)
{
bool Ok = false;
int leNo = caused->objectName().right(1).toInt(&Ok);
Q_ASSERT(Ok);
foreach(QLineEdit *le, this->findChildren<QLineEdit *>() )
{
if ( le->objectName().startsWith("out", Qt::CaseInsensitive) && le->objectName().right(1) == QString::number(leNo) )
{
QLineEdit *incomingLE = qobject_cast<QLineEdit *>(caused);
Q_ASSERT(incomingLE != NULL);
le->setText(incomingLE->text());
}
}
}