20200102-2 QML 加入 QCharts 控件之后无法启动程序

问题:

启用 在 QML 中使用 ChartView 等图形控件无法启动

解决方案:
  1. 确认 pro 文件中已经加载该 charts 模块 QT += charts
  2. 修改 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 替换。

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值