PDA

View Full Version : Emit signal to different widget



unix7777
12th August 2012, 08:07
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.

spirit
12th August 2012, 08:56
dialog.h


class Dialog : public QDialog
{
Q_OBJECT
...
signals:
void enteredText(const QString &text);
...
};


dialog.cpp


void Dialog::on_pushButton_pressed()
{
emit enteredText(ui->lineEdit->text());
...
}

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();
}


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.

unix7777
12th August 2012, 09:04
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.

unix7777
13th August 2012, 19:47
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*)'



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?

spirit
13th August 2012, 19:49
Remove "&" before "dialog" in the connection.

unix7777
13th August 2012, 20:17
:-1: error: symbol(s) not found for architecture x86_64

spirit
14th August 2012, 06:21
What's "symbol"?
Provide full error message as you see in the output window.