QT 6.5.2中ArrayBuffer转QByteArray失败问题求助
QT 6.5.2中ArrayBuffer转QByteArray失败问题求助
各位大佬好,我最近碰到一个头疼的问题:我在项目里尝试把QML中的ArrayBuffer传递给C++处理函数,转换成QByteArray使用。这个逻辑在Qt 6.5.1里运行完全正常,但升级到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; } };
想请教大家几个问题:
- 有没有人能确认这个问题在Qt 6.5.2里确实存在?
- 有没有大佬知道解决办法或者临时的workaround?
- 这会不会是Qt的一个回归bug?
备注:内容来源于stack exchange,提问作者Jürgen Lutz
相关产品推荐
相关产品推荐

