Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChart Problem

QChart Problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 110 Views
  • 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
    Dhanu1973
    wrote last edited by
    #1

    Hi,

    I am getting following error:

    Out of memory in C:\Users\qt\work\qt\qtbase\include\QtCore../../src/corelib/tools/qvector.h, line 709

    when i try to plot large chunks of data using QChart. Here is my code below:

    /****************************************************************************
    **
    ** Copyright (C) 2016 The Qt Company Ltd.
    ** Contact: https://www.qt.io/licensing/
    **
    ** This file is part of the Qt Charts module of the Qt Toolkit.
    **
    ** $QT_BEGIN_LICENSE:GPL$
    ** Commercial License Usage
    ** Licensees holding valid commercial Qt licenses may use this file in
    ** accordance with the commercial license agreement provided with the
    ** Software or, alternatively, in accordance with the terms contained in
    ** a written agreement between you and The Qt Company. For licensing terms
    ** and conditions see https://www.qt.io/terms-conditions. For further
    ** information use the contact form at https://www.qt.io/contact-us.
    **
    ** GNU General Public License Usage
    ** Alternatively, this file may be used under the terms of the GNU
    ** General Public License version 3 or (at your option) any later version
    ** approved by the KDE Free Qt Foundation. The licenses are as published by
    ** the Free Software Foundation and appearing in the file LICENSE.GPL3
    ** included in the packaging of this file. Please review the following
    ** information to ensure the GNU General Public License requirements will
    ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
    **
    ** $QT_END_LICENSE$
    **
    ****************************************************************************/
    
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QMainWindow>
    #include <QtCharts/QChartView>
    #include <QtCharts/QLineSeries>
    #include <QValueAxis>
    #include <QList>
    #include <QApplication>
    #include <QDebug>
    #include <QTimer>
    #include <QRandomGenerator>
    #include <QElapsedTimer>
    #include <QObject>
    QT_CHARTS_USE_NAMESPACE
    
    int iBatchCnt = 1;
    int iSCnt = 0;
    int iNoRecs = 1200000;
    int iBatch = iNoRecs / 10;
    QElapsedTimer *etmr1;
    
    QChart *chart;
    QLineSeries *series;
    QList<int> iYVals;
    QChartView *chartView;
    QTimer timer;
    QValueAxis *axisX, *axisY;
    int iRndVal;
    int iTmrVal = 2000;
    
    void plt1() {
        if(iSCnt < iNoRecs) {
            chart->removeSeries(series);
            for(; iSCnt < iBatchCnt * iBatch; ++iSCnt) {
                series->append(iSCnt, iYVals[iSCnt]);
            }
            chart->addSeries(series);
            chart->setAxisX(axisX, series);
            chart->setAxisY(axisY, series);
            qInfo() << "BatchCnt:" << iBatchCnt;
            ++iBatchCnt;
            iTmrVal += 2000;
            timer.setInterval(iTmrVal);
        } else {
            qInfo() << "Plottng Completed.";
            timer.stop();
        }
    }
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QObject::connect(&timer, &QTimer::timeout, plt1);
    
        int iVal = 0;
    //![1]
        series = new QLineSeries;
    //![1]
    
    //![2]
        for(int i = 0; i < iNoRecs; ++i) {
            iRndVal = QRandomGenerator::global()->bounded(-500, 500);
            iYVals.append(iRndVal);
        }
    //![2]
    
    //![3]
        chart = new QChart;
        chart->legend()->hide();
        chart->addSeries(series);
    //    chart->createDefaultAxes();
    
        axisX = new QValueAxis;
        axisX->setTitleText("<b><font size='3'>Samples</font></b>");
        axisX->setRange(0, iNoRecs);
        axisX->setTickCount(10);
        axisX->setLabelFormat("%d");
        chart->setAxisX(axisX, series);
    
        axisY = new QValueAxis;
        axisY->setTitleText("<b><font size='3'>Angular Rate (deg/s)</font></b>");
        axisY->setRange(-600, 600);
        axisY->setTickCount(13); // 25
        axisY->setLabelFormat("%d");
        chart->setAxisY(axisY, series);
    
    
        chart->setTitle("Simple line chart example");
    //![3]
    
    //![4]
        chartView = new QChartView(chart);
        chartView->setRenderHint(QPainter::Antialiasing);
    //![4]
    
    
    //![5]
        QMainWindow window;
        window.setCentralWidget(chartView);
        window.resize(1500, 800);
        window.show();
    //![5]
    
        timer.start(iTmrVal);
    
        return a.exec();
    }
    
    

    I kindly request you to let me know how i can resolve this?

    thank you.
    Dan

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dhanu1973
      wrote last edited by
      #2

      i am getting this error after 12 - 13 timer interval batches.

      JonBJ 1 Reply Last reply
      0
      • D Dhanu1973

        i am getting this error after 12 - 13 timer interval batches.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote last edited by
        #3

        @Dhanu1973
        Since each timer interval plots one batch and a batch is one tenth of all points to plot I don't know how you manage "12 - 13 timer interval batches" in the first place....

        That aside, don't try to plot 1.2 million points. A 1080p screen only has 2 million pixels anyway. I don't know how much spare memory you have or whether it should run out but there you are.

        Qt Charts is being phased out anyway in favour of Qt Graphs so you're not going to get "fixes" or similar now. You could try Qt Graphs to see whether it makes any difference.

        1 Reply Last reply
        2

        • Login

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