Results 1 to 3 of 3

Thread: Transfering data from a dialog to the mainwindow

  1. #1
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Transfering data from a dialog to the mainwindow

    So I have a Mainwindow application with a QTextEdit field. When a user clicks the addComment button, it opens up a dialog with another QTextEdit field. I need to know how to transfer what the user entered in the Comment TextEdit to the Mainwindow TextEdit, then it puts the date and time stamp into the TextEdit field. Currently, I just have a QMessageBox on the MainWindow, but that can only have a QLineEdit, and that is difficult to see line breaks.

    I guess long story short, how do I transfer info from a dialog to a main window? I have been combing this forum and the tutorials and cannot find anything.

    Thanks in advance,

    fnmblot
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

  2. #2
    Join Date
    Jan 2007
    Posts
    68
    Thanks
    9
    Thanked 8 Times in 8 Posts

    Default Re: Transfering data from a dialog to the mainwindow

    If your dialog is a standard dialog just look @ the standard dialog example.

    If you use a custom dialog you have to emit a SIGNAL inside your dialog and connect this signal with a slot in your mainwindow:

    Qt Code:
    1. //inside dialog e.g. when button clicked or something...
    2. QString text = "test";
    3. emit setText(text);
    4.  
    5. //inside mainwindow
    6. if (!myDialog)
    7. {
    8. myDialog= new MyDialog(this);
    9. connect(myDialog, SIGNAL(setText(const QString &)), mainwindow, SLOT(setText(const QString &)));
    10.  
    11. }
    12. myDialog->show();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Transfering data from a dialog to the mainwindow

    Thanks a million for the reply. But before I saw your reply, I found another way to do it in a different post and came up with this:
    Qt Code:
    1. void addComment::enterComment()
    2. {
    3. QDateTime dt = QDateTime::currentDateTime();
    4. QString todaysDateTimeString = dt.toString();
    5.  
    6. QString commentText = commentTextEdit->toHtml();
    7.  
    8. ((nnDBSMainWindow*)parent())->ui.textEdit->insertPlainText(todaysDateTimeString);
    9. ((nnDBSMainWindow*)parent())->ui.textEdit->insertPlainText("\n");
    10. ((nnDBSMainWindow*)parent())->ui.textEdit->insertHtml(commentText);
    11. ((nnDBSMainWindow*)parent())->ui.textEdit->insertPlainText("\n******************************");
    12. ((nnDBSMainWindow*)parent())->ui.textEdit->insertPlainText("\n");
    13. ((nnDBSMainWindow*)parent())->ui.addCommentPB->setEnabled(true);
    14. }
    To copy to clipboard, switch view to plain text mode 
    I know it might be like reaching over my shoulder to scratch my butt, but it gets the job done. Efficiency will be the next step.
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

Similar Threads

  1. Replies: 3
    Last Post: 17th May 2007, 14:50
  2. Opening a Dialog from a MainWindow FileMenu
    By nbkhwjm in forum Newbie
    Replies: 4
    Last Post: 17th April 2007, 13:24
  3. Replies: 3
    Last Post: 23rd July 2006, 19:02
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 13:53

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.