[vtk-developers] Fwd: QVTKWidget segfault on Linux with Qt5, VTK6.2, GCC4.9, C++14

Marcus D. Hanwell marcus.hanwell at kitware.com
Mon Jan 12 20:52:35 EST 2015


On Mon, Jan 12, 2015 at 8:41 PM, Júlio Hoffimann
<julio.hoffimann at gmail.com> wrote:
>> Hi Marcus,
>>
>> I tried to add the orientation marker as a member in the viewer class but
>> the program is still crashing. What is the exact modification you did in the
>> code?
>>
>> -Júlio
>
>
> You mean I need to do these two modifications (Register(NULL) and turn the
> widget a member of the class) to actually solve the problem?

You must ensure the reference count of the widget remains above one,
http://www.kitware.com/source/home/post/7 is a Source article I wrote
that goes over the smart pointer classes, and how they might be used
in your own classes. You need to structure your code such that the VTK
classes are not deleted until the window is closed, currently you have
a number of classes instantiated in the example constructor, going out
of scope. Many of them are added to the render window, and so are not
deleted. This is not true of the widget.

Calling the Register member is a terrible solution for a real program,
you can see in the example class how the various smart pointers might
be used (and the pros and cons of each one).

Marcus


More information about the vtk-developers mailing list