Results 1 to 5 of 5

Thread: passing data when closing a dialog

  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default passing data when closing a dialog

    I have a main dialog which invokes another dialog (using .exec()) to get the user to enter a string when the close button is pressed I want to pass that string back to the main dialog. How do I do this? I tried emiting a signal but this crashes the application.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: passing data when closing a dialog

    after executing the dialog, get the value of your lineedit through a self defined getter method. E.g.:
    Qt Code:
    1. MyDialog dlg;
    2. switch(dlg.exec())
    3. {
    4. //...
    5. dlg.getMyLineEditValue();
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    jimiq (4th November 2009)

  4. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: passing data when closing a dialog

    using references is another way to do it.

  5. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: passing data when closing a dialog

    using references is another way to do it.
    Do you have an example of this?

  6. #5
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: passing data when closing a dialog

    in the constructor of teh dialog, just send a variable by reference.

    for instance:

    Qt Code:
    1. class CmyDialog : public QDialog
    2. {
    3. public:
    4. CmyDialog (QString& myString, QWidget *parent = 0);
    5. ~CmyDialog ();
    6.  
    7. //change myString in your code
    8. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QString strIwantMyDataBack;
    2. CmyDialog _MyDialog(strIwantMyDataBack, this);
    3. _MyDialog.exec();
    To copy to clipboard, switch view to plain text mode 


    For your interest

Similar Threads

  1. Closing a dialog using a button
    By srohit24 in forum Qt Programming
    Replies: 5
    Last Post: 21st July 2009, 05:57
  2. Dialog is not closing
    By manmohan in forum Newbie
    Replies: 5
    Last Post: 1st December 2008, 17:04
  3. Replies: 3
    Last Post: 17th May 2007, 13:50
  4. closing dialog in hidden main Widget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2006, 10:35

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.