Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSharedPointer from a raw pointer

I currently have something like this:

QSharedPointer<t> Qsharedfoo;

Now I have a raw pointer to foo as well called rawfoo. How can I make foo point own the raw pointer and start pointing to it. I know in boost with shared pointers we could use boost::make_shared how do we do it with QSharedPointer ?

I want to do something like this:

Qsharedfoo = rawfoo
like image 536
MistyD Avatar asked Jan 11 '23 11:01

MistyD


1 Answers

Straight from the Qt documentation, we have something like this:

QSharedPointer<MyObject> obj = QSharedPointer<MyObject>(new MyObject);

You can basically pass your pointer in the same fashion:

// Here I assume that T is the class you're using for Qsharedfoo.
QSharedPointer<T> Qsharedfoo = QSharedPointer<T>(rawfoo);
like image 59
Huy Avatar answered Jan 18 '23 09:01

Huy