在以下代码片段中,我尝试将
ArrayBuffer
从 QML 传输到 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;
}
};
任何人都可以确认这在 6.5.2 中不起作用吗? 有人对此有解决办法或解决方法吗? 这是 QT 回归错误吗?
这是一个已知错误 (https://bugreports.qt.io/browse/QTBUG-115733),已在 6.5.3 中修复。