1 Attachment(s)
Emit signal to different widget
I have being searching in the net for solution of this problem and every body write advices but obviously for all like me that ask is hard to understand it without see the code.Because of that i write an example and only need to be written the part i and many others in the net don't understand.
There is a main widget with a Label and button.When click the button a new Dialog opens which contains lineEdit field and a close button.
How we can get the text from dialog's lineEdit field and when close the dialog to set it to the main widget label.
Please see the attached simple project.
Re: Emit signal to different widget
dialog.h
Code:
{
Q_OBJECT
...
signals:
void enteredText
(const QString &text
);
...
};
dialog.cpp
Code:
void Dialog::on_pushButton_pressed()
{
emit enteredText(ui->lineEdit->text());
...
}
proba.cpp
Code:
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();
}
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::on_pushButton_pressed a connection between the dialog and the main window is established.
That's it.
Re: Emit signal to different widget
Spirit,
You can't imagine how much you helped me!
Thank you a lot for spending this time to help me and many others like me.I hope some day i can help to people like me too.
Re: Emit signal to different widget
I want to close widget when dialog is closed.
I'm trying to do so but with another signal/slot and it gives me an error:
clients.cpp:49: error: no matching function for call to 'Clients::connect(GroupsAddDialog**, const char*, QTableView*&, const char*)'
Code:
void Clients::on_pushButton_add_pressed()
{
GroupsAddDialog *dialog=new GroupsAddDialog(this);
connect(&dialog, SIGNAL(updateTable()), ui->tableView_clients, SLOT(close()));
dialog->show();
}
By the way is it the best approach in order to refresh content inside QtableView?
I read that somebody subclass the class but i thing there should be some method for that?
Re: Emit signal to different widget
Remove "&" before "dialog" in the connection.
Re: Emit signal to different widget
:-1: error: symbol(s) not found for architecture x86_64
Re: Emit signal to different widget
What's "symbol"?
Provide full error message as you see in the output window.