dialog.h
{
Q_OBJECT
...
signals:
void enteredText
(const QString &text
);
...
};
class Dialog : public QDialog
{
Q_OBJECT
...
signals:
void enteredText(const QString &text);
...
};
To copy to clipboard, switch view to plain text mode
dialog.cpp
void Dialog::on_pushButton_pressed()
{
emit enteredText(ui->lineEdit->text());
...
}
void Dialog::on_pushButton_pressed()
{
emit enteredText(ui->lineEdit->text());
...
}
To copy to clipboard, switch view to plain text mode
proba.cpp
void Proba::on_pushButton_pressed()
{
// Dialog *d=new Dialog();
// d->show();
Dialog d(this);
connect(&d,
SIGNAL(enteredText
(QString)), ui
->label,
SLOT(setText
(QString)));
d.exec();
}
void Proba::on_pushButton_pressed()
{
// Dialog *d=new Dialog();
// d->show();
Dialog d(this);
connect(&d, SIGNAL(enteredText(QString)), ui->label, SLOT(setText(QString)));
d.exec();
}
To copy to clipboard, switch view to plain text mode
1. In dialog.h a new signals is declared -- eteredText.
2. In dialog.cpp by pressing on the button the signal is emitted (using emit) with proper value.
3. In proba.cpp in Proba:n_pushButton_pressed a connection between the dialog and the main window is established.
That's it.
Bookmarks