Access Qt UI of another Class from the MainWindow Class

Viewed 152

I want to understand if the following sequence is possible? If yes, how can we achieve the same?

  1. MainWindow Qt GUI has a QPushButton
  2. While we click on the QPushButton, it must open another Qt GUI Window (a different class, say 'DialogClass')
  3. In the newly opened Qt GUI Window we have a QLineEdit and QPushButton
  4. While we enter data in the QLineEdit and click on the QPushButton (of the DialogClass) the MainWindow class should receive the data entered in QLineEdit

Any help on this item will be appreciated. Thanks in advance!

1 Answers

Qt foresees its signals and slots approach for such purposes.

The QPushButton of your class offers a signal clicked which you connect to a custom (self-written) slot of your dialog. The dialog's slot then should read the contents of the QLineEdit and publish these on the dialogs own (custom) signal, which is connected to a (custom) slot of your main window, which then can process the value originally contained in the line edit.

Details will resemble pretty much the example of Qt's signals and slots documentation, so I won't be more explicit about.

Related