c++ - 当 C++ SLOT 函数尝试与从 QML 获得的输入进行交互时崩溃
问题描述
我有这样的事情导致我的程序崩溃
void BackEnd::updateChart(QtCharts::QChartView *view)
{
QList<QObject*> children = view->children();
}
在 QML 方面:
backend.updateChart(chartView);
其中“backend”是 QT 对象“BackEnd”的一个实例,“chartView”是 QML 类型“ChartView”的一个实例
我尝试在我的 BackEnd 构造函数上运行以下命令,但这并没有帮助
qRegisterMetaType<QtCharts::QChartView*>();
解决方案
ChartView
is not a QChartView
, ChartView
is a DeclarativeChart that is a QQuickItem
of the private api that handles the same data of QChartView but it is not a QChartView
. So the solution is to change QtCharts::QChartView
to QQuickItem
or QObject
.
void BackEnd::updateChart(QQuickItem /*or QObject*/ *view)
{
QList<QObject*> children = view->children();
}
if you print view with qDebug()
you get:
QtCharts::DeclarativeChart(0xfoo_address, parent=0x0, geometry=0,0 400x300)
推荐阅读
- javascript - 禁用嵌套 HTML 中的所有链接
- php - 计算具有相同索引或不同索引的多维数组的总和
- ios - 无法在我的物理 iPhone 设备上运行我的应用程序?
- python - RuntimeError:无效参数 0:张量的大小必须匹配,但维度 0 除外
- ssl - 读取 base64 编码证书的内容
- android - 将查看器转换为全屏
- algorithm - 二次算法何时可以比对数算法更好?
- pdf-generation - 如何在 Heroku 上使用 CombinePDF 和 Rails 6 (ActiveStorage)
- opengl-es - OES_depth_texture 和 glReadPixels
- javascript - 如何异步注入 React 组件?