mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-16 14:15:57 -06:00
[GH-ISSUE #148] QByteArray support #92
Labels
No labels
bug
enhancement
help wanted
help wanted
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/qmlnet#92
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @geigertom on GitHub (Jul 1, 2019).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/148
I'm trying to pass a QByteArray containing raw image data to my registered .net object by attaching to the emitted signal of a QVideoFilter that I wrote in c++.
The connection works, and I can pass objects, e.g. QString to the signal listener:
But apparently QByteArray is not (yet) supported:
Unsupported variant type: QVariant::QByteArray QByteArrayI tried converting it to a QVariantList beforehand, which actually works, but the conversion on each frame takes far to much time to be usable in real time image processing.
Is it possible to pass QByteArray or a simple byte array to .net? What would be the aproach to extend qml.net to support types like QByteArray? I would love to help implement this feature but I need a little push in the right direction.
Thanks,
Tom
@pauldotknopf commented on GitHub (Jul 1, 2019):
This is interesting.
I'd say just pass a pointer to the raw byte array, but QByteArray is ref counted, and it may be deleted from underneath you. You'd definately want to maintain an instance of QByteArray to copy the contents to a .net array at a later time.
Adding this support would be easy.
I'd say update
NetVariantto support a newNetVariantTypeofQByteArray. Then you'd haveNetVariant.SetBytes(byte[]) andbyte[] NetVariant.GetBytes()```.However, this means that you'll never be able to modify
QByteArrayfrom .NET, since you'd only be sending receiving raw .NET byte arrays.If you need the instance of
QByteArrayin .NET so that you could maybe pass the raw pointer somewhere else, or modify it directly, you could implement something likeINetJsValue, but call itINetQByteArray. That would have methods for you to modify the internal instance ofQByteArray.What approach would be best for you? We could support both.
@geigertom commented on GitHub (Jul 2, 2019):
For my use case I don't need an instance of the
QByteArrayin .NET, a raw .NET byte array would be just fine. I will take a look atNetVariantand see what I can do to extend it the way you suggested.@pauldotknopf commented on GitHub (Jul 2, 2019):
You'd have to marshal that yourself, it isn't blittable. The best bet would be to make
net_variant_getBytestake in a c-style callback that passes in raw pointer and the number of bytes, for you to then marshal in .NET.@pauldotknopf commented on GitHub (Jul 2, 2019):
@geigertom commented on GitHub (Jul 2, 2019):
Thanks, I realize that I need to read more on the concept of marshalling to gain a better understanding.
@geigertom commented on GitHub (Jul 3, 2019):
I finally got it working:
I will create a PR in the next few days as soon I find the time.