V
V
Vitaly2014-05-06 19:12:56
Qt
Vitaly, 2014-05-06 19:12:56

How to implement two-way communication between C++ MainWindow mdiSubWindow GraphicsScene classes?

There is an MDI application based on MainWindow.
MainWindow contains a lot of DockWidgets, inside of which I placed toolboxes and a properties window for elements.
Child windows contain the "left" QWidget (which he defined himself) with QGraphicsView stretched to the full width and height of the widget, taking up all its space. Inside the same widget, I create an object of the QGraphicsScene class, also custom.
Task:
in addition to the ability to access from MainWindow directly to the scene, for example, to read data from an array and change the order and toolboxes in accordance with the contents of the document from objects (for example, when switching between child windows, we already have this). But also to provide the ability to "call" the MainWindow directly from the scene, for example, I selected an element, and I want to immediately display its characteristics in the properties panel located in the MainWindow, either by clicking on the element or by using the context menu command.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy, 2014-05-06
@Wohlstand

Well, I solved the problem myself!
Sharing with those who are asking the same question:
To do this, I used the "outer pointer" method to provide scene feedback to the MainWindow.
Thanks for the tip to one of my Austrian friend.
1) create a static pointer (just in case, I packed it inside the class)

class MainWinConnect
{
public:
    static MainWindow * pMainWin;
};

and somewhere we create a body for the same pointer:
2) In the constructor of our MainWindow class, we simply write the address of ourselves directly into our pointer:
3) Now it has become possible to access MainWindow functions from almost anywhere, even if the object of the MyScene class is created directly inside MainWindow itself.
class MainWindow
{
   public:
      void callMe(int someData);
     ...
   MyScene * scene;
}

void MyScene::doSomething()
{
       ...
       MainWinConnect::pMainWin->callMe(1234);
       ...
}

Disadvantage of the method: suitable for single classes, so it is better to perform any callbacks through signal slots, or place all important pointers directly in the child class

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question