Error when adding chart to main.qml
-
I want to add line chart to the main.qml but it cause error. I tried to search for the error on the internet but I couldn't find anything. This is my error code:
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Layouts 1.12 import QtQuick.Controls 2.5 import QtCharts 2.15 import "./source" import MyCppObject 1.0 ApplicationWindow { visible: true width: 700 height: 480 title: qsTr("Hello World") CppObject{ //c++object id:cpp_obj } VersionPage{ //Version window object id:ver } header:ToolBar{ font.pixelSize: 20 font.bold: true RowLayout{ Button{ text: "Version" onClicked: { ver.visible=true } } Button{ text: "Clear" onClicked: { //myDisPlayView.clearDisplayText() } } } } GridLayout{ anchors.fill: parent columns: 2 columnSpacing: 2 rowSpacing: 2 anchors.margins: 7 Rectangle{ id: rect width: 200 Layout.fillHeight: true height: 5 border.color: "gray" border.width: 1 //anchors.margins: 1 SettingView{ id:mySettingView anchors.margins: 2 anchors.fill: parent Layout.fillWidth: false } } ColumnLayout{ Layout.alignment: rect.right anchors.margins: 1 Rectangle{ Layout.fillHeight: true Layout.fillWidth: true Layout.columnSpan:2 border.width: 1 border.color: "gray" height: 4 //*************** Error field**************** ChartView { id: line anchors.fill:parent LineSeries { name: "LineSeries" XYPoint { x: 0 y: 2 } XYPoint { x: 1 y: 1.2 } XYPoint { x: 2 y: 3.3 } XYPoint { x: 5 y: 2.1 } } } //************************************************* } Rectangle{ Layout.fillWidth: true Layout.fillHeight: true width: 2 border.color: "gray" border.width: 1 //Display data interface DisplayView{ id:myDisPlayView anchors.fill: parent } } } } }
- When I remove the error field, it works normally.
- I want to add line chart to "chart here" location.
-
Use a
QApplication
instead of aQGuiApplication
. The Charts module depends on Qt Widgets. -
@GrecKo thank you very much. This error took a lot of my time.