Re: How to return a value to a parent window
I have a problem that will probably be something very simple to solve but I can't seem to find it on the web.
I have a window that shows a table from a MySQL database. I created a find dialog box which opens and allows the user to find an item from the table. The results of the find are shown below the find dialog box in a tableview. When a user selects the item he was searching for he clicks on a button select which in turn opens the product window with the current index shown.
The problem is that I create a new window of the product every time I find something. Is there a way to go back to the original product window and simple use the index returned by the find dialog box to set the mapper index to?
Thanks,
Pericles
Added after 44 minutes:
I kind of solved the problem. I am not sure how crude is my solution.
I called the find dialog box using exec() and then created a getIndex() function to return the index value of the found item.
Now to get the correct index value.
Pericles
Re: How to return a value to a parent window
Two ways to do this.
1. Pass the handle of the parent window to the dialog and call the required function directly (you can also get the parent handle from parent() call)
2. Create a signal in the dialog and connect to a slot in the parent while creating the dialog.
I prefer the second one, this way dialog is independent of parent.
Re: How to return a value to a parent window
@ Santosh Reddy
hi sir
about this sentence: "2. Create a signal in the dialog and connect to a slot in the parent while creating the dialog.
"
please explain a bit.
thanks in advance.
Re: How to return a value to a parent window
Re: How to return a value to a parent window
hi dear Chris !!!
i knew Signals & Slots. please explain ....
lol
10Q
Re: How to return a value to a parent window
So if you know signals and slots then what other explanation do you need? I think Santosh told you exactly what to do.
Re: How to return a value to a parent window
I am having a similar issue to pcheng. I am able to write information to dialogs by doing something like
Code:
dialog
->ui
->textEdit
->setText
(QString);
However, I do not know how to do it vice versa; therefore, retrieve the data from the dialog and use it in the main window. Santosh mentioned signals and slots, but I don't really know anything about those and the documentation isn't very easy to understand.
Seeing as this is the Newbie Forum, do you think you could guide us through this?
Re: How to return a value to a parent window
Quote:
Originally Posted by
sberl
I am having a similar issue to pcheng. I am able to write information to dialogs by doing something like
Code:
dialog
->ui
->textEdit
->setText
(QString);
However, I do not know how to do it vice versa; therefore, retrieve the data from the dialog and use it in the main window.
Code:
dialog->ui->textEdit->text()
?
Re: How to return a value to a parent window
maybe i wasn't clear. that is how i would go about writing information to a dialog. but, i need to extract the information from the dialog and use it in my main window after clicking an OK button
Re: How to return a value to a parent window
Maybe you're still not clear. What text() does is that it returns a value. You can't set (aka write) anything using that method.
Re: How to return a value to a parent window
when OK button clicked in your dialog window, you can emit a signal that contains whole of dialog information and connect this signal to main window slot.
Re: How to return a value to a parent window
@wysota. i don't know what your talking about. it seems to work fine for me
Code:
Dialog_Test *testdialog = new Dialog_Test(this);
testdialog->setWindowTitle("Test Dialog");
testdialog->ui->textBoxInDialog->setText(mystring);
@Ali Reza
I know this is going to cause outrage, but how do I emit a signal, i can set one up
Code:
testdialog.h
signals:
int emitSignal();
testdialog.cpp
int emitSignal()
{
return myint;
}
but how do I connect that with anything.
Re: How to return a value to a parent window
Quote:
Originally Posted by
sberl
@wysota. i don't know what your talking about. it seems to work fine for me
Code:
Dialog_Test *testdialog = new Dialog_Test(this);
testdialog->setWindowTitle("Test Dialog");
testdialog->ui->textBoxInDialog->setText(mystring);
Compare your code to mine.
Re: How to return a value to a parent window
Quote:
Originally Posted by
wysota
Compare your code to mine.
'text' : is not a member of 'QLineEdit'
Re: How to return a value to a parent window
That's sad because the docs say it is -- QLineEdit::text
Re: How to return a value to a parent window
by commamd:
emit signalFunctionName;