Passing variables from one form to another in Qt

qt

Solution

The dialog box still exists after it closes. So you can, from the main form, do something like this:

QString text = subform->textEdit->text();

This assumes your dialog box is `subform` and the name you gave to the text edit box is `textEdit`. Make sure you make `textEdit` public in the designer.

If you don't want to make `textEdit` public, then you can add a getter to `subform`.

Problem

I've got two forms, the mainform which opens up a dialog box that has a text box in it. How can I pass the text from the textbox back to the mainform? I've tried alot of different methods but I think I'm missing something simple. Thanks for any help.

Original source