Results 1 to 7 of 7

Thread: Emit signal to different widget

  1. #1
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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.
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Emit signal to different widget

    dialog.h
    Qt Code:
    1. class Dialog : public QDialog
    2. {
    3. Q_OBJECT
    4. ...
    5. signals:
    6. void enteredText(const QString &text);
    7. ...
    8. };
    To copy to clipboard, switch view to plain text mode 

    dialog.cpp
    Qt Code:
    1. void Dialog::on_pushButton_pressed()
    2. {
    3. emit enteredText(ui->lineEdit->text());
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 
    proba.cpp
    Qt Code:
    1. void Proba::on_pushButton_pressed()
    2. {
    3. // Dialog *d=new Dialog();
    4. // d->show();
    5. Dialog d(this);
    6. connect(&d, SIGNAL(enteredText(QString)), ui->label, SLOT(setText(QString)));
    7. d.exec();
    8. }
    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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.

  4. #4
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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*)'


    Qt Code:
    1. void Clients::on_pushButton_add_pressed()
    2. {
    3. GroupsAddDialog *dialog=new GroupsAddDialog(this);
    4. connect(&dialog, SIGNAL(updateTable()), ui->tableView_clients, SLOT(close()));
    5. dialog->show();
    6. }
    To copy to clipboard, switch view to plain text mode 

    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?

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Emit signal to different widget

    Remove "&" before "dialog" in the connection.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Emit signal to different widget

    :-1: error: symbol(s) not found for architecture x86_64

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Emit signal to different widget

    What's "symbol"?
    Provide full error message as you see in the output window.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. How to decide which SIGNAL to emit?
    By TheIndependentAquarius in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2011, 15:09
  2. Replies: 2
    Last Post: 3rd May 2011, 20:22
  3. emit signal from script
    By wookoon in forum Newbie
    Replies: 5
    Last Post: 6th July 2010, 14:37
  4. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 14:26
  5. emit a signal
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2006, 11:14

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.