[vtkusers] return vtkSmartPointers from a function or signal/slot

Shawn Waldon swaldon at cs.unc.edu
Wed Aug 14 12:51:02 EDT 2013


Hi Miro,

Most of your questions about vtkSmartPointer are answered in this tutorial:
http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers

I'll let someone else handle the Qt signal/slots questions since I haven't
tried to do that.  But I would point out that VTK is not thread-safe, so if
you are trying to use this mechanism to communicate between threads make
sure you know what you are getting into first.

HTH,
Shawn


On Wed, Aug 14, 2013 at 12:45 PM, Miro Drahos <mdrahos at robodoc.com> wrote:

>  Hi all,
> I am having really hard times passing on reference to the objects that are
> stored as vtkSmartPointer<T> as private data within a class. E.g.:
> class MyClass
> {
>   public:
>     ...
>    private:
>     vtkSmartPointer<vtkPolyData> surface;
> };
>
> What is the best way to pass 'surface' via signal/slot mechanism of Qt?
> I thought I'd create a public method
> vtkPolyData * MyClass::getSurface() { return surface.GetPointer(); }
> The problem is that GetPointer() returns *const* T* which the compiler
> complains about when I later want to use it. As a matter of fact, all
> vtkSmartPointer's public methods return const something.
>
> What would be the preferred way to pass objects stored as
> vtkSmartPointer<T> object?
> 1.) T* MyClass::getT() const { return object.GetPointer(); }
> 2.) vtkSmartPointer<T> MyClass::getT() { return object; }
> 3.) something else?
>
> I want to pass the object via signal/slot mechanism. What would be the
> best way?
> A.) signal doneSurfaceProcessing(vtkPolyData &);
> B.) signal doneSurfaceProcessing(vtkPolyData *);
> C.) signal doneSurfaceProcessing(vtkSmartPointer<vtkPolyData>);
>
> The idea is to send off the signal with something like
> emit doneSurfaceProcessing(myclass->getSurface());
>
> then the slot would be
> setSurface(???)  //vtkSmartPointer<T>  or T* or T& ?
>
> Thank you!!
> Miro
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>


-- 
Shawn Waldon
Graduate Research Assistant
Department of Computer Science
University of North Carolina at Chapel Hill
swaldon at cs.unc.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130814/b2efa43b/attachment.htm>


More information about the vtkusers mailing list