Results 1 to 4 of 4

Thread: Return values from QDialog to MainWindow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Return values from QDialog to MainWindow

    The pattern for a modal dialog is usually this

    1. create dialog instance
    2. call exec() on that instance
    3. read values using getter methods

    Cheers,
    _

  2. #2
    Join Date
    Apr 2015
    Posts
    28
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    4

    Default Re: Return values from QDialog to MainWindow

    Like this?

    Qt Code:
    1. def openAddDialog(self):
    2. print "running openAddDialog..."
    3. diag = AddDevice()
    4. diag.exec_()
    5. print diag.getIPv4(), diag.getUsername(), diag.getPassword()
    To copy to clipboard, switch view to plain text mode 

    Does not seem like a good way to go, the values will be read if the user cancels/aborts the dialog window. This is exactly what I can't get my head around. I want the buttons and it's slots in the dialog class, but the values from the fields should be sent to or read from the MainWindow.
    Last edited by ecce; 16th April 2015 at 20:43.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Return values from QDialog to MainWindow

    This is a brilliant way to do what you want

    exec() returns if the dialog was accepted or rejected (= canceled) so just use this information and read or do not read the username etc.

Similar Threads

  1. Containers and return values
    By tuamadre71 in forum Newbie
    Replies: 0
    Last Post: 15th January 2012, 12:04
  2. return-value and QDialog
    By homerun4711 in forum Newbie
    Replies: 4
    Last Post: 16th February 2011, 16:34
  3. Replies: 10
    Last Post: 10th February 2011, 19:45
  4. how to program custom Dialogs with return values
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2006, 00:37
  5. How to return something not int with a QDialog
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2006, 17:05

Tags for this Thread

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.