Hello everyone, first of all I just start learning Qt.

I have MainWindow class defined in "mainwindow.h" and "mainwindow.cpp" files.
The "Dialog" and "Dialog_2" classes are friend classes of that MainWindow class.
An object of "MainWindow" class is parent of "Dialog" and "Dialog_2" type objects.
But I cannot access the members of MainWindow from both of that friend classes.
From the function "void Dialog_2::add_new_person()", I am trying to access the data_map member of parent object, but I cannot do that.

The code is:

"mainwindow.h"
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class MainWindow;
  8. }
  9.  
  10. class MainWindow : public QMainWindow
  11. {
  12. friend class Dialog;
  13. friend class Dialog_2;
  14. Q_OBJECT
  15. .......
  16. }
To copy to clipboard, switch view to plain text mode 

"mainwindow.cpp"
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "dialog.h"
  4. #include "dialog_2.h"
  5.  
  6. MainWindow::MainWindow(QWidget *parent) :
  7. QMainWindow(parent),
  8. ui(new Ui::MainWindow)
  9. {
  10. ui->setupUi(this);
  11. }
  12. .....
To copy to clipboard, switch view to plain text mode 

"dialog_2.h"
Qt Code:
  1. #ifndef DIALOG_2_H
  2. #define DIALOG_2_H
  3.  
  4. #include <QDialog>
  5.  
  6. class MainWindow;
  7.  
  8. namespace Ui {
  9. class Dialog_2;
  10. }
  11.  
  12. class Dialog_2 : public QDialog
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. explicit Dialog_2(QWidget *parent = 0);
  18. ~Dialog_2();
  19.  
  20. private slots:
  21. void on_pushButton_clicked();
  22. void on_pushButton_2_clicked();
  23.  
  24. private:
  25. Ui::Dialog_2 *ui;
  26. void add_new_person();
  27. };
  28.  
  29. #endif // DIALOG_2_H
To copy to clipboard, switch view to plain text mode 

"dialog_2.cpp"
Qt Code:
  1. #include "dialog_2.h"
  2. #include "ui_dialog_2.h"
  3. #include <QMessageBox>
  4. #include <QDebug>
  5. #include "mainwindow.h"
  6.  
  7. Dialog_2::Dialog_2(QWidget *parent) :
  8. QDialog(parent),
  9. ui(new Ui::Dialog_2)
  10. {
  11. ui->setupUi(this);
  12. }
  13.  
  14. Dialog_2::~Dialog_2()
  15. {
  16. delete ui;
  17. }
  18.  
  19. void Dialog_2::on_pushButton_clicked()
  20. {
  21. add_new_person();
  22. close();
  23. }
  24.  
  25. void Dialog_2::on_pushButton_2_clicked()
  26. {
  27. close();
  28. }
  29.  
  30. void Dialog_2::add_new_person()
  31. {
  32. QString new_name = ui->lineEdit_1->text();
  33. QString new_number = ui->lineEdit_2->text();
  34.  
  35. this->parent()->data_map.insert(new_name, new_number);
  36.  
  37. QMessageBox::information(this, "Added!", new_name + " has added successfully!");
  38. }
To copy to clipboard, switch view to plain text mode 

It's same for dialog.h class, so I didnot add the code.

Thanks for your help