c++qtqmlarraybufferqbytearray

ArrayBuffer to QByteArray conversion failes for QT 6.5.2


In following code snippets, I try to transfer an ArrayBuffer from QML to a C++ handler, where it is supposed to get converted into a QByteArray. This is working in QT 6.5.1 but stopped working in 6.5.2.

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickItem>

#include "ComboBoxHandler.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    // register the class with the QML engine
    auto handler = new ComboBoxHandler();
    qmlRegisterSingletonInstance("ComboBoxHandler", 1, 0, "ComboBoxHandler", handler);

    QQmlApplicationEngine engine;
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
    &app, []() { QCoreApplication::exit(-1); },
    Qt::QueuedConnection);

    const QUrl url(u"qrc:/TestBench/main.qml"_qs);
    engine.load(url);
    return app.exec();

}

main.qml

import QtQuick
import QtQuick.Window
import QtQuick.Controls

import ComboBoxHandler

ApplicationWindow
{
    id: mainWindow
    width: 600
    height: 400
    visible: true

    Button {
        text: "test"

        onClicked: {
            // fill in some data into the ArrayBuffer
            let data = [];
            for (let i = 0; i < 10; ++i) {
                data.push(i);
            }
            // send ArrayBuffer to handler
            ComboBoxHandler.onItemChanged(data)
        }
     }
}

ComboBoxHandler.h

#pragma once

#include <QObject>
#include <QDebug>

class ComboBoxHandler: public QObject {
    Q_OBJECT
public slots:
    void onItemChanged(const QByteArray& newValue) {
        // I would expect the data here.
        // works in QT 6.5.1 and stopped working in 6.5.2
        qDebug() << "Value: " << newValue;
    }
};

Can anyone confirm, that this is not working in 6.5.2? Has anyone a fix or a workaround for this? Is this a QT regression bug?


Solution

  • This is a known bug (https://bugreports.qt.io/browse/QTBUG-115733) and is fixed in 6.5.3.