I have a mainWindow application which can start 3 sub-applications. Each of the sub-applications can be started independently or through the main application so each of those sub-applications is also a mainWindow application.
One of the sub-applications (A) also can be started from another sub-application (B).
When I start (A) from (B), (A) is a mainWindow which I set to applicationModal, I get the required behaviour: (B) is not responding as long as (A) is open.
My problem is if the same scenario happens but when (B) is started from the top mainWindow application, things don't work as I want.

In the top mainWindow I have:
Qt Code:
  1. B * firstChild;
  2. firstChild= new B(this);
  3.  
  4. // earlier in the code - QWorkspace * workspace; and setCentralWidget(workspace);
  5. workspace->addWindow(firstChild);
  6. firstChild->setAttribute(Qt::WA_DeleteOnClose);
  7. firstChild->setAttribute(Qt::WA_NoMousePropagation);
  8. firstChild->show()
To copy to clipboard, switch view to plain text mode 

In application B:
Qt Code:
  1. A * secondChild;
  2. secondChild= new A(this);
  3. secondChild->setAttribute(Qt::WA_DeleteOnClose);
  4. secondChild->setWindowModality(Qt::ApplicationModal);
  5. secondChild->show();
To copy to clipboard, switch view to plain text mode 

As the code looks above - secondChild window is opened outside the workspace window and firstChild is not available until secondChild is closed (good).
But I want the secondChild window to open inside the same workspace as the firstChild window. So before I show secondChild, I add the line:
Qt Code:
  1. static_cast<QWorkspace*>( static_cast<QMainWindow*>(parent)->centralWidget() )->addWindow(secondChild);
To copy to clipboard, switch view to plain text mode 

This opens the secondChild window in the workspace but I cannot set the modality properly - it seems to lock the whole application and I cannot click on anything (not even secondChild window).

What Am I doing wrong?