Hello!
I have two windows in an application. The idea is to upload a text document on a window(main window) and to use it FROM other windows(childwindows), without having to upload the document again once the user is on one of the childwindows. To get the document on the main window, a button is required and a path to the file is shown. Having the document on the main window, any path shoul be required from the childwindows and also, any button for this purpose is not needed on the childwindows. That means, the document should be retrieved from the text widget of the main window.

The bottle neck is at the line 29 of one of the childwindows. With this line, I want to get to the text document of the main window. Previously, I have created an instance of the main window. While compiling, I have the following error message: M_myText is private. In this code, I though I could use the friendship, but this would suppress the encapsulation, so that I do not thing it is the good idea. The heritage would also not be the good idea.

My question is the following:

How can I get to the (and the) document I've uploaded on the main window from one of my childwindows?

Any help would be welcome.

Many thanks in advance.

Here is my code

Main window:
Qt Code:
  1. #include <QtGui>
  2.  
  3. class MyMainWindow: public QMainWindow
  4. {
  5. Q_OBJECT
  6.  
  7. public:
  8. explicit MyMainWindow();
  9. virtual ~MyMainWindow();
  10.  
  11.  
  12. public slots:
  13. void openFile();
  14.  
  15. private:
  16. QAction *m_open;
  17. QTextEdit *m_myText;
  18. QWidget *m_centralZone;
  19. QMenu *m_menuFile;
  20. QLineEdit *m_openAFile;
  21. };
  22.  
  23. MyMainWindow::MyMainWindow() : QMainWindow()
  24. {
  25. m_menuFile = menuBar()->addMenu("&File");
  26.  
  27. m_myText = new QTextEdit(m_centralZone);
  28.  
  29. m_open = m_menuFile->addAction("Open a file");
  30.  
  31. m_openAFile = new QLineEdit;
  32.  
  33. connect(m_open, SIGNAL(triggered()), this, SLOT(openFile()));
  34.  
  35. setCentralWidget(m_centralZone);
  36. }
  37.  
  38. void MyMainWindow::openFile()
  39. {
  40. QString file = QFileDialog::getOpenFileName(this, "Information", "Open", "*.text");
  41. m_openAFile->setText(file);
  42. }
To copy to clipboard, switch view to plain text mode 

One of the childwindows

Qt Code:
  1. #include<QtGui>
  2. #include"myMainWindow"
  3.  
  4. class ChildWindow: public QWidget
  5. {
  6. Q_OBJECT
  7.  
  8. public:
  9. explicit ChildWindow(QWidget *parent = 0);
  10. virtual ~ChildWindow();
  11.  
  12. public slots:
  13. void operation2(myMainWindow &aFile, QString &doc);
  14.  
  15. private:
  16.  
  17. };
  18.  
  19.  
  20. #include "ChildWindow.h"
  21. #include "myMainWindow.h"
  22.  
  23. ChildWindow::ChildWindow(QWidget *parent)
  24. : QWidget(parent)
  25. {
  26. }
  27. void ChildWindow::operation2(myMainWindow &aFile, QString &doc)
  28. {
  29. doc = aFile.m_myText.text();
  30. }
  31.  
  32.  
  33. ChildWindow::~ChildWindow()
  34. {
  35. ;
  36. }
To copy to clipboard, switch view to plain text mode