问题:
启用 在 QML 中使用 ChartView 等图形控件无法启动
解决方案:
- 确认 pro 文件中已经加载该 charts 模块 QT += charts
- 修改 main 函数
删去 QGuiApplication app(argc, argv);
改为 QApplication app(argc, argv);
原因:
官方注解
Note: Since Qt Creator 3.0 the project created with Qt Quick Application wizard based on Qt Quick 2 template uses QGuiApplication by default. As Qt Charts utilizes Qt Graphics View Framework for drawing, QApplication must be used. The project created with the wizard is usable with Qt Charts after the QGuiApplication is replaced with QApplication.
大概内容,就是从 Qt Creator 3.0 开始 默认使用 QGuiApplication 基于 Qt Quick 2 架构,但是 Qt Charts 使用利用 Qt Graphics 绘图架构绘制的,所以必须使用 QApplication 替换。