Results 1 to 10 of 10

Thread: Connecting from a dialog to mainWindow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Connecting from a dialog to mainWindow

    You can forward the signal from the Dialog's line edit
    Qt Code:
    1. class Dialog : public QDialog
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit Dialog(QWidget *parent = 0);
    6.  
    7. signals:
    8. void textChanged(const QString &text);
    9. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Dialog::Dialog(QWidget *parent)
    2. : QDialog(parent)
    3. , ui(....)
    4. {
    5. connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
    6. }
    To copy to clipboard, switch view to plain text mode 
    And then connect that signal in your main window to whatever slot you want.

    Cheers,
    _

  2. #2
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Connecting from a dialog to mainWindow

    Is there any advantage behind forwarding the signal to another signal
    Qt Code:
    1. connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
    To copy to clipboard, switch view to plain text mode 
    over just emitting a new signal such as ?
    Qt Code:
    1. emit sendText(ui->lineEdit->text());
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Connecting from a dialog to mainWindow

    Quote Originally Posted by toufic.dbouk View Post
    Is there any advantage behind forwarding the signal to another signal
    Qt Code:
    1. connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
    To copy to clipboard, switch view to plain text mode 
    over just emitting a new signal such as ?
    Qt Code:
    1. emit sendText(ui->lineEdit->text());
    To copy to clipboard, switch view to plain text mode 
    It depends on what the goal is.

    Given the thread starter's question it looks like the goal is a synchronisation between two line edits.
    For that goal the forwarding is "nicer" because you don't need a slot just to emit a signal again and the signal/signal connect makes the forwarding very obvious when reading the code.

    In the example you gave, i.e. reacting to a button, the slot plus explicit emit is the only possible choice.

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    toufic.dbouk (11th October 2013)

  5. #4
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Connecting from a dialog to mainWindow

    Alright got it anda_skoa.
    Thanks for the explanation.

  6. #5
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connecting from a dialog to mainWindow

    Hi,
    Your problem is like this thread http://www.qtcentre.org/threads/5647...ng-error/page2
    I have created a sample code from above link (signal and slot using QmainWindow and QDialog).
    You can check that and I hope get idea how to solve your problem.

    Best regards,

    Toto

  7. #6
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Connecting from a dialog to mainWindow

    Hello, if you are addressing me , i dont have a problem.
    My question was if there is any advantages of one way over the other.
    Good Luck.

Similar Threads

  1. Using Variables From Dialog In MainWindow
    By steadi in forum Newbie
    Replies: 2
    Last Post: 7th October 2012, 23:18
  2. How to call a dialog from a mainwindow
    By luiz4um in forum Qt Programming
    Replies: 26
    Last Post: 29th June 2010, 10:41
  3. Open Dialog from MainWindow.
    By halvors in forum Qt Programming
    Replies: 8
    Last Post: 1st April 2010, 01:09
  4. Communication between MainWindow and a dialog
    By Backslash in forum Newbie
    Replies: 9
    Last Post: 3rd August 2007, 04:27
  5. Replies: 2
    Last Post: 23rd May 2007, 03:51

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.