找回密码
 立即注册
收起左侧

如何在工程中使用ChartView?在线等,急急急!!!!!

3
回复
9099
查看
[复制链接]
累计签到:3 天
连续签到:1 天
来源: 2016-12-22 18:40:12 显示全部楼层 |阅读模式
10Qter豆
      嗯,最近在用ChartView,嗯,遇到坑了。嗯,这很Qt。嗯,吐槽完毕。
      话说如何在工程中使用ChartView控件?下面这段代码无法运行,注意是无法运行,不是无法编译。事实上如果使用qmlscence是可以看到效果的,但是在工程文件中就是不行。
  1. import QtQuick 2.7
  2. import QtQuick.Controls 2.0
  3. import QtCharts 2.1

  4. ApplicationWindow {
  5.     visible: true
  6.     width: 640
  7.     height: 480
  8.     title: qsTr("Hello World")

  9.     SwipeView {
  10.         id: swipeView
  11.         anchors.fill: parent
  12.         currentIndex: tabBar.currentIndex

  13.         Page {
  14.             ChartView {
  15.                 title: "Line"
  16.                 anchors.fill: parent
  17.                 antialiasing: true

  18.                 LineSeries {
  19.                     name: "LineSeries"
  20.                     XYPoint { x: 0; y: 0 }
  21.                     XYPoint { x: 1.1; y: 2.1 }
  22.                     XYPoint { x: 1.9; y: 3.3 }
  23.                     XYPoint { x: 2.1; y: 2.1 }
  24.                     XYPoint { x: 2.9; y: 4.9 }
  25.                     XYPoint { x: 3.4; y: 3.0 }
  26.                     XYPoint { x: 4.1; y: 3.3 }
  27.                 }
  28.             }
  29.         }

  30.         Page{
  31.             Label{
  32.                 anchors.centerIn: parent;
  33.                 text:"Page 2"
  34.             }
  35.         }
  36.     }

  37.     footer: TabBar {
  38.         id: tabBar
  39.         currentIndex: swipeView.currentIndex
  40.         TabButton {
  41.             text: qsTr("First")
  42.         }
  43.         TabButton {
  44.             text: qsTr("Second")
  45.         }
  46.     }
  47. }
复制代码
运行输出为:
Starting D:\MAP\build-TestChart-Desktop_Qt_5_7_0_MinGW_32bit-Debug\debug\TestChart.exe...
QML debugging is enabled. Only use this in a safe environment.
ASSERT: "!"No style available without QApplication!"" in file kernel\qapplication.cpp, line 1123
ASSERT: "!"No style available without QApplication!"" in file kernel\qapplication.cpp, line 1123
D:\MAP\build-TestChart-Desktop_Qt_5_7_0_MinGW_32bit-Debug\debug\TestChart.exe exited with code 255

话说这段Chart的代码来源于手册,被搞得没脾气了,不知道怎么办才好。

回复

使用道具 举报

累计签到:3 天
连续签到:1 天
2016-12-22 21:00:18 显示全部楼层
本帖最后由 adadadda 于 2016-12-22 22:07 编辑

菜的抠脚的我,解决了。工程中忘了增加几个模块导致了这样的结果。
回复

使用道具 举报

尚未签到

2016-12-23 00:22:22 显示全部楼层
pro里面加上就行了咯,能自己解决就好
回复

使用道具 举报

累计签到:3 天
连续签到:1 天
2016-12-23 07:59:17 显示全部楼层
Joey_Chan 发表于 2016-12-23 00:22
pro里面加上就行了咯,能自己解决就好

谢谢回复。。。。。。。。。。。。。。。。。。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了