[PR #150] [MERGED] QByteArray support #225

Closed
opened 2026-05-05 11:21:10 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/qmlnet/qmlnet/pull/150
Author: @geigertom
Created: 7/4/2019
Status: Merged
Merged: 7/9/2019
Merged by: @pauldotknopf

Base: developHead: qbytearray_support


📝 Commits (4)

  • f38b38f Added QByteArray support
  • 758e3d3 Remove blank lines
  • 5e8544b Support null byte arrays.
  • e431882 Increasing the number of allowed registered types for unit tests.

📊 Changes

13 files changed (+247 additions, -27 deletions)

View changed files

📝 src/native/QmlNet/QmlNet.h (+2 -1)
📝 src/native/QmlNet/QmlNet/qml/NetQObjectArg.cpp (+3 -0)
📝 src/native/QmlNet/QmlNet/qml/NetValueMetaObjectPacker.cpp (+3 -0)
📝 src/native/QmlNet/QmlNet/qml/NetVariant.cpp (+33 -0)
📝 src/native/QmlNet/QmlNet/qml/NetVariant.h (+2 -0)
📝 src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.cpp (+20 -0)
src/net/Qml.Net.Tests/Qml/ByteArrayTests.cs (+59 -0)
📝 src/net/Qml.Net.Tests/Qml/NetVariantTests.cs (+15 -0)
📝 src/net/Qml.Net/Internal/CodeGen/CodeGen.Methods.cs (+27 -0)
📝 src/net/Qml.Net/Internal/CodeGen/CodeGen.cs (+34 -25)
📝 src/net/Qml.Net/Internal/Helpers.cs (+2 -0)
📝 src/net/Qml.Net/Internal/Qml/NetVariant.cs (+45 -0)
📝 src/net/Qml.Net/NetVariantType.cs (+2 -1)

📄 Description

Added support for QByteArray.

Create QByteArray in .NET using byte[]:

[NotifySignal("byteArrayPropertyChanged")]
public byte[] ByteArrayProperty { get; set; } = new byte[]{1,3,6,8};

Receive QByteArray in .NET:

public void Process(dynamic o) {
    byte[] bytes = (byte[])o;
    Console.WriteLine("Received byte array size: " + bytes.Length);
    ...
}

In QML, there is no direct way to access QByteArray objects, they are, however, implicitly converted to javascript ArrayBuffer objects [see: Qt docs] which can be used like this:

function logValue() {
    var data = new Uint8Array(netObject.byteArrayProperty)
    console.log("first element from byte array: " + data[0]);
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/qmlnet/qmlnet/pull/150 **Author:** [@geigertom](https://github.com/geigertom) **Created:** 7/4/2019 **Status:** ✅ Merged **Merged:** 7/9/2019 **Merged by:** [@pauldotknopf](https://github.com/pauldotknopf) **Base:** `develop` ← **Head:** `qbytearray_support` --- ### 📝 Commits (4) - [`f38b38f`](https://github.com/qmlnet/qmlnet/commit/f38b38fcb155355e8dc82ca0275a5cd1bdee581f) Added QByteArray support - [`758e3d3`](https://github.com/qmlnet/qmlnet/commit/758e3d3746bfa167f3100095b805f7dcd44f27d1) Remove blank lines - [`5e8544b`](https://github.com/qmlnet/qmlnet/commit/5e8544b9e210e86fe96ae2897c4841bad2e17f3c) Support null byte arrays. - [`e431882`](https://github.com/qmlnet/qmlnet/commit/e4318826b48abda73c4b9d0e3f8169d4d163014a) Increasing the number of allowed registered types for unit tests. ### 📊 Changes **13 files changed** (+247 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `src/native/QmlNet/QmlNet.h` (+2 -1) 📝 `src/native/QmlNet/QmlNet/qml/NetQObjectArg.cpp` (+3 -0) 📝 `src/native/QmlNet/QmlNet/qml/NetValueMetaObjectPacker.cpp` (+3 -0) 📝 `src/native/QmlNet/QmlNet/qml/NetVariant.cpp` (+33 -0) 📝 `src/native/QmlNet/QmlNet/qml/NetVariant.h` (+2 -0) 📝 `src/native/QmlNet/QmlNet/qml/QQmlApplicationEngine.cpp` (+20 -0) ➕ `src/net/Qml.Net.Tests/Qml/ByteArrayTests.cs` (+59 -0) 📝 `src/net/Qml.Net.Tests/Qml/NetVariantTests.cs` (+15 -0) 📝 `src/net/Qml.Net/Internal/CodeGen/CodeGen.Methods.cs` (+27 -0) 📝 `src/net/Qml.Net/Internal/CodeGen/CodeGen.cs` (+34 -25) 📝 `src/net/Qml.Net/Internal/Helpers.cs` (+2 -0) 📝 `src/net/Qml.Net/Internal/Qml/NetVariant.cs` (+45 -0) 📝 `src/net/Qml.Net/NetVariantType.cs` (+2 -1) </details> ### 📄 Description Added support for `QByteArray`. Create `QByteArray` in .NET using `byte[]`: ``` [NotifySignal("byteArrayPropertyChanged")] public byte[] ByteArrayProperty { get; set; } = new byte[]{1,3,6,8}; ``` Receive `QByteArray` in .NET: ``` public void Process(dynamic o) { byte[] bytes = (byte[])o; Console.WriteLine("Received byte array size: " + bytes.Length); ... } ``` In QML, there is no direct way to access `QByteArray` objects, they are, however, implicitly converted to javascript `ArrayBuffer` objects [see: [Qt docs](https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#qbytearray-to-javascript-arraybuffer)] which can be used like this: ``` function logValue() { var data = new Uint8Array(netObject.byteArrayProperty) console.log("first element from byte array: " + data[0]); } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 11:21:10 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/qmlnet#225
No description provided.