I've created a simple custom QDialog with three QLineEdits. When clicking the "OK" button I want to read the entered text and return them to the MainWindow object where the values will be stored in a list.

How do I return the values from the QDialog class so I can store them in the list in the MainWindow class, and how do I call it properly?

This is the code I have at the moment:

Qt Code:
  1. class MainWindow(QtGui.QMainWindow):
  2.  
  3. deviceList = []
  4.  
  5. def openAddDialog(self):
  6. print "running openAddDialog..."
  7. diag = AddDevice()
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. from PySide.QtGui import *
  2.  
  3. class AddDevice(QDialog):
  4.  
  5. def __init__(self):
  6. QDialog.__init__(self)
  7. self.setWindowTitle("Add Device")
  8. self.resize(400, 300)
  9.  
  10. iLabel = QLabel("IPv4 address:")
  11. self.iText = QLineEdit()
  12.  
  13. uLabel = QLabel("Username:")
  14. self.uText = QLineEdit()
  15.  
  16. pLabel = QLabel("Password:")
  17. self.pText = QLineEdit()
  18.  
  19. okButton = QPushButton()
  20. okButton.setText("OK")
  21. okButton.clicked.connect(self.add)
  22.  
  23. frame = QFrame(self)
  24.  
  25. formLayout = QFormLayout(frame)
  26. formLayout.addRow(iLabel, self.iText)
  27. formLayout.addRow(uLabel, self.uText)
  28. formLayout.addRow(pLabel, self.pText)
  29. formLayout.addRow(okButton, okButton)
  30.  
  31. self.exec_()
  32.  
  33. def add(self):
  34. ipv4 = self.iText.text()
  35. username = self.uText.text()
  36. password = self.pText.text()
  37.  
  38. print ipv4, username, password
To copy to clipboard, switch view to plain text mode