PDA

View Full Version : QWidget with a return value



klenze
23rd November 2011, 13:39
Hi,


is it possible to create a small QWidget with some QLineEdits, which returns the content of these QLineEdits after closing the QWidget?
Or is a QDialog more suitable to implment this functionality?

Thanks

Micha

qlands
23rd November 2011, 13:44
Hi,

A QDialog is useful when you want the user to take a decision before continuing a process. For example, ask for an answer before deleting a file. If this is the case, use QDialog.

Carlos.

klenze
23rd November 2011, 13:51
Ok, then I should use a QWidget, because the user shall enter some values in QLineEdits and after closing the widget these values should be available in the parent window.

qlands
23rd November 2011, 13:57
That depends. You can call QDialog with exec() so it appears as modal (the user cannot interact with other windows (including the parent) until it close the dialog). If the user can interact with the parent while the window with edits is on the screen then you can use a QDialog but calling show() or a QWidget.

klenze
23rd November 2011, 14:05
OK, if I would use QDialog with the exec function. How can I return the values from the QLineEdits to the parent widget?

qlands
23rd November 2011, 14:22
ok You create a C++ class based on QDialog. Using QT designer for example. Say you called it myDialogWithEdits.

This class has in its ui the edits. Because the ui is private you need to create a public function to get the value from the edits. Lets call it getValueOfEditOne().

in the .h


public:
QString getValueOfEditOne();


in the .cpp


myDialogWithEdits::getValueOfEditOne()
{
return ui->edit1->text();
{


The in the parent you do:


QDialog myDialogWithEdits;
myDialogWithEdits.exec(); //This will call modal and wait until its closes

//This will be executed after it closes
ui->edit1->setText(myDialogWithEdits.getValueOfEditOne());


Carlos

klenze
23rd November 2011, 15:04
Thanks, it works perfect!