s4eed
s4eed

Reputation: 7891

Force QByteArray to take ownership of passed C-Style array to its constructor

You may know that you can create a QByteArray from a raw pointer, using one of its constructors, or QByteArray::fromRawData. The former will deep copy the raw pointer so you have to pay the cost, but the later will just use the pointer. None of them takes ownership of the pointer. Is there any other method to create a QByteArray from a raw pointer, which not only takes ownership of the pointer but also doesn't deep copy the pointer?

Upvotes: 2

Views: 308

Answers (1)

Mihayl
Mihayl

Reputation: 3911

No, there is no way to pass the ownership to the QByteArray. This would require the class to support a custom cleanup handler just like the QScopedPointer.

Upvotes: 2

Related Questions