PDA

View Full Version : Transfering data from a dialog to the mainwindow



fnmblot
22nd May 2007, 21:53
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

darksaga
23rd May 2007, 02:57
If your dialog is a standard dialog just look @ the standard dialog example (http://doc.trolltech.com/4.3/dialogs-standarddialogs.html).

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:



//inside dialog e.g. when button clicked or something...
QString text = "test";
emit setText(text);

//inside mainwindow
if (!myDialog)
{
myDialog= new MyDialog(this);
connect(myDialog, SIGNAL(setText(const QString &)), mainwindow, SLOT(setText(const QString &)));

}
myDialog->show();

fnmblot
23rd May 2007, 03:51
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:

void addComment::enterComment()
{
QDateTime dt = QDateTime::currentDateTime();
QString todaysDateTimeString = dt.toString();

QString commentText = commentTextEdit->toHtml();

((nnDBSMainWindow*)parent())->ui.textEdit->insertPlainText(todaysDateTimeString);
((nnDBSMainWindow*)parent())->ui.textEdit->insertPlainText("\n");
((nnDBSMainWindow*)parent())->ui.textEdit->insertHtml(commentText);
((nnDBSMainWindow*)parent())->ui.textEdit->insertPlainText("\n******************************");
((nnDBSMainWindow*)parent())->ui.textEdit->insertPlainText("\n");
((nnDBSMainWindow*)parent())->ui.addCommentPB->setEnabled(true);
}

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.