[Interest] void pointers

Phil Hannent phil at hannent.co.uk
Wed Jul 17 10:07:58 CEST 2013


On 17 July 2013 05:30, Mandeep Sandhu <mandeepsandhu.chd at gmail.com> wrote:

> On Tue, Jul 16, 2013 at 9:19 PM, Phil Hannent <phil at hannent.co.uk> wrote:
>
>> Hi,
>>
>> I have a codebase that is using a C library and Qt. I have some legacy
>> code where structs from the C library are stored in a Qt/C++ class using:
>>
>> void *userData;
>>
>> Is this an example where I should replace the void * with a
>> QSharedPointer or a QWeakPointer?
>>
>
> The answer would depend on whether you're sharing this pointer with other
> classes and/or whether your class is taking ownership of this data.
>
> If it's for private use within your Qt/C++ class then, as other have said,
> you don't need a shared ptr.
>
> However, if you're sharing this data with others, and they can potentially
> delete it, then it's a good idea to keep it as a shared ptr.
>

The pointer is currently stored as part of a QAction so that when the
action is triggered it can be handed back to the C library for use. It
sounds from the feedback that I am better off keeping it the way that it
is, rather than complicate matters by placing it into a Qt object.

Thanks for the feedback all of you.
Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130717/3801994e/attachment.html>


More information about the Interest mailing list