Results 1 to 16 of 16

Thread: How to return a value to a parent window

  1. #1
    Join Date
    Jun 2012
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default 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
    Last edited by pcheng; 15th June 2012 at 10:46.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default 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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Platforms
    Unix/X11 Windows Android
    Thanks
    5

    Default 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.
    Life is about making the right decisions and moving on.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to return a value to a parent window


  5. #5
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Platforms
    Unix/X11 Windows Android
    Thanks
    5

    Default Re: How to return a value to a parent window

    hi dear Chris !!!
    i knew Signals & Slots. please explain ....
    lol
    10Q
    Life is about making the right decisions and moving on.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. dialog->ui->textEdit->setText(QString);
    To copy to clipboard, switch view to plain text mode 
    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to return a value to a parent window

    Quote Originally Posted by sberl View Post
    I am having a similar issue to pcheng. I am able to write information to dialogs by doing something like
    Qt Code:
    1. dialog->ui->textEdit->setText(QString);
    To copy to clipboard, switch view to plain text mode 
    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.
    Qt Code:
    1. dialog->ui->textEdit->text()
    To copy to clipboard, switch view to plain text mode 
    ?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Platforms
    Unix/X11 Windows Android
    Thanks
    5

    Default 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.
    Life is about making the right decisions and moving on.

  12. #12
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. Dialog_Test *testdialog = new Dialog_Test(this);
    2. testdialog->setWindowTitle("Test Dialog");
    3. testdialog->ui->textBoxInDialog->setText(mystring);
    To copy to clipboard, switch view to plain text mode 

    @Ali Reza
    I know this is going to cause outrage, but how do I emit a signal, i can set one up
    Qt Code:
    1. testdialog.h
    2. signals:
    3. int emitSignal();
    4.  
    5. testdialog.cpp
    6. int emitSignal()
    7. {
    8. return myint;
    9. }
    To copy to clipboard, switch view to plain text mode 
    but how do I connect that with anything.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to return a value to a parent window

    Quote Originally Posted by sberl View Post
    @wysota. i don't know what your talking about. it seems to work fine for me
    Qt Code:
    1. Dialog_Test *testdialog = new Dialog_Test(this);
    2. testdialog->setWindowTitle("Test Dialog");
    3. testdialog->ui->textBoxInDialog->setText(mystring);
    To copy to clipboard, switch view to plain text mode 
    Compare your code to mine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to return a value to a parent window

    Quote Originally Posted by wysota View Post
    Compare your code to mine.
    'text' : is not a member of 'QLineEdit'

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to return a value to a parent window

    That's sad because the docs say it is -- QLineEdit::text
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Platforms
    Unix/X11 Windows Android
    Thanks
    5

    Default Re: How to return a value to a parent window

    by commamd:
    emit signalFunctionName;
    Life is about making the right decisions and moving on.

Similar Threads

  1. resizing child window with parent window
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2012, 19:02
  2. open window in parent mdi
    By ShapeShiftme in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2011, 06:07
  3. Replies: 5
    Last Post: 21st April 2010, 21:36
  4. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40
  5. Replies: 11
    Last Post: 4th June 2008, 07:22

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
  •  
Qt is a trademark of The Qt Company.