Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Error when adding chart to main.qml
Forum Updated to NodeBB v4.3 + New Features

Error when adding chart to main.qml

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 507 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Duc Nguyen
    wrote on last edited by
    #1

    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
    
                    }
                }
            }
    
        }
    
    }
    
    

    29c1f794-7e4e-415c-8361-50d9ff97c359-image.png

    • When I remove the error field, it works normally.
    • I want to add line chart to "chart here" location.
      6c9d899f-61d8-4c7e-bbe7-0b43bb18fd7c-image.png
    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by GrecKo
      #2

      Use a QApplication instead of a QGuiApplication. The Charts module depends on Qt Widgets.

      D 1 Reply Last reply
      1
      • GrecKoG GrecKo

        Use a QApplication instead of a QGuiApplication. The Charts module depends on Qt Widgets.

        D Offline
        D Offline
        Duc Nguyen
        wrote on last edited by
        #3

        @GrecKo thank you very much. This error took a lot of my time.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved