[vtkusers] RE: Qt4 QMdiArea::addSubWindow() deletes VTK render window

John Platt jcplatt at dsl.pipex.com
Tue Oct 2 17:28:56 EDT 2007


Hi Clint,

Many thanks for taking the time to investigate.

I basically took the example C:\Qt\4.3.1\examples\mainwindows\mdi and
changed MdiChild to C:\VTK\VTK_5_Source\Examples\GUI\Qt\SimpleView.
Looking more closely, SimpleView is a main window.

Anyway you are spot on! Removing WA_DeleteOnClose in the MdiChild
constructor solves the problem. QMdiSubWindow::addSubWindow()sets this
attribute on the QMdiSubWindow as you suggest. I presume this is
inherited by all the children.

I wondered if you could suggest where the best place is to set the
default size of the QMdiSubWindow. At present I do

    QMdiSubWindow* mdiSubWindow = mdiArea->addSubWindow( mdiChild );
    mdiSubWindow->resize(560, 398);

but when I cascade the mdi-subwindows, they all end up (0,0).

Thanks again for you help.

John.


-----Original Message-----
From: clinton at elemtech.com [mailto:clinton at elemtech.com] 
Sent: 02 October 2007 18:00
To: jcplatt at dsl.pipex.com
Cc: vtkusers at vtk.org
Subject: Re: Qt4 QMdiArea::addSubWindow() deletes VTK render window


> When I add a child window derived from QVTKWidget to a QMdiArea,
>     QMdiSubWindow* mdiSubWindow = mdiArea->addSubWindow( mdiChild );
> the VTK render window created in the mdiChild constructor
>
> MdiChild::MdiChild()
> {
>     setAttribute(Qt::WA_DeleteOnClose);

Shouldn't you be setting that delete on close attribute on the
QMdiSubWindow 
instead?

>     isUntitled = true;
>
>     // QT/VTK interact
>     ren = vtkRenderer::New();
>     this->GetRenderWindow()->AddRenderer( ren );
> }
>
> is deleted when addSubWindow() returns.

The only way the render window gets deleted is if you call 
SetRenderWindow(NULL) is called or if you delete the QVTKWidget.  In
other 
words, the lifetime of the vtkRenderWindow is tied to the lifetime of
the 
QVTKWidget, unless you disconnect it, or hold references elsewhere.

> Calling GetRenderWindow() again appears to fix the problem.
> I was wondering if anybody else using QMdiArea has had the same
problem
> ( Qt 4.3.1 open source edition, VTK 5.1, VS6, Win XP ).

I just threw together a quick mdi app trying to mirror what you were
doing, 
and didn't see any problems.  If your problem still persists, can you
send me 
an example?

Clint





More information about the vtkusers mailing list